<?php

use App\Models\homeModel;

$HomeModel = new homeModel();
$WebsitesDomain = $HomeModel->GetAllWebsitesDomain();
?>


<div class="modal fade add_user_modal_lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"
     aria-hidden="true" data-keyboard="false" data-backdrop="static">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Add User</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <form  class="validate" method="post" action="#" id="AddUserForm">
                    <div class="row">
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="full_name" class="col-form-label">Full Name:</label>
                                <input type="text" class="form-control validate[required]" name="full_name" id="full_name">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="password" class="col-form-label">Username:</label>
                                <input type="text" name="username" class="form-control validate[required]" id="username">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="password" class="col-form-label">Password:</label>
                                <input type="text" name="password" class="form-control validate[required]" id="password">
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <label for="user_type" class="col-form-label">Type:</label>
                                <select class="form-control validate[required]" name="user_type" id="user_type">
                                    <option value="" selected disabled>Please Select</option>
                                    <option value="admin">Admin</option>
                                    <option value="user">User</option>
                                </select>
                            </div>
                        </div>

                    </div>
                    <div class="row">
                        <div class="col-md-12">
                            <h5> Websites </h5>
                        </div>
                        <div class="col-md-12">
                            <hr style="margin-bottom: 10px;">
                        </div>
                        <div class="col-md-12">
                            <?php
                            foreach ($WebsitesDomain as $value) {
                                echo '<label class="checkbox-primary" style="margin-right: 10px;">
                                            <input id="' . $value['UID'] . '" type="checkbox" class="" value="1"
                                                   name="websites[' . $value['UID'] . ']" style="margin-right: 7px;">
                                            <strong>' . ucwords($value['WebSchema']) . '</strong>
                                      </label>';
                            }
                            ?>

                        </div>


                    </div>
                    <div class="row">
                        <div class="col-md-12" id="Status">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary" type="submit" onclick="SaveUserData()">Save</button>
            </div>
        </div>
    </div>
</div>

<script>
    function SaveUserData() {

        var validate = $("form#AddUserForm").validationEngine('validate');
        if (validate == false) {
            return false;
        }

        var phpdata = $("form#AddUserForm").serialize();
        var response = AjaxResponse("user/save_add_user_form", phpdata);
        if (response.status == 'success') {
            setTimeout(function () {
                $("#Status").html('<div class="text-center alert alert-success mb-4" role="alert">  <strong>' + response.message + '</strong> </div>');
                location.reload();
            }, 1000);
        }
    }


</script>
