<?php
$title = 'Administrator';
require_once('header-links.php');
// require_once('../lib/basic-function.php');
// require_once('../lib/user-functions.php');
// require_once('../lib/investment-plan-functions.php');
// require_once('../lib/package-functions.php');
// require_once('../lib/currency-functions.php');
$all_admin = $basicFunctn->selectAllDlt($basicFunctn->admin_tb);
?>

<body>
    <div class="app">
        <div class="layout">
            <?php require_once('sidebar.php'); ?>

            <!-- Page Container START -->
            <div class="page-container">
                <?php require_once('header.php'); ?>

                <!-- Content Wrapper START -->
                <div class="main-content">
                    <div class="container-fluid">
                        <div class="page-title">
                            <h4><?php print $title; ?></h4>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="card">
                                    <div class="card-block">
                                        <div class="row">
                                            <div class="col-md-8  ml-auto mr-auto">
                                                <form class="form-horizontal mrg-top-40 new_admin_form">
                                                <!-- $_POST['create_admin_name'],$_POST['email'],$_POST['password'],$_POST['c_password'],$_POST['level'] -->
                                                    <div class="form-group row">
                                                        <label for="form-1-1" class="col-md-3 control-label">
                                                            Full Name
                                                        </label>
                                                        <div class="col-md-9">
                                                            <input type="text" value="" class="form-control" name="create_admin_name" placeholder="">
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">
                                                        <label for="form-1-1" class="col-md-3 control-label">Email</label>
                                                        <div class="col-md-9">
                                                            <input type="text" value="" class="form-control" name="email" placeholder="">
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">
                                                        <label for="form-1-1" class="col-md-3 control-label">
                                                            Level
                                                        </label>
                                                        <div class="col-md-9">
                                                            <select name="level" class="form-control">
                                                                <option value="">--Administrator Level--</option>
                                                                <option value="1">Main</option>
                                                                <option value="2">Sub</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">
                                                        <label for="form-1-1" class="col-md-3 control-label">Password</label>
                                                        <div class="col-md-3">
                                                            <input type="password" value="" class="form-control" name="password" placeholder="">
                                                        </div>
                                                        <label for="form-1-1" class="col-md-3 control-label">
                                                        Confirm Password
                                                        </label>
                                                        <div class="col-md-3">
                                                            <input type="password" value="" class="form-control" name="c_password" placeholder="">
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">
                                                        <div class="col-md-11 col-xs-11">
                                                            <div class="text-right">
                                                                <button type="submit" id="referrer_percent" class="btn btn-primary new_admin_btn">Create Admin</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="card">
                                    <div class="card-block">
                                        <div class="table-responsive">
                                            <table class="table table-bordered table-hover table-sm">
                                                <thead>
                                                    <tr>
                                                        <th>S/N</th>
                                                        <th>Full Name</th>
                                                        <th>Email</th>
                                                        <th>Level</th>
                                                        <th>Block / Unblock</th>
                                                        <th>Remove</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php
                                                    $i = 1;
                                                    foreach ($all_admin as $e) {                    
                                                         ?>
                                                        <tr>
                                                            <td><?php print $i; ?></td>
                                                            <td class="text-capitalize"><?php print $e['full_name']; ?></td>
                                                            <td class="status-done"><?php print $e['email']; ?></td>
                                                            <td><?php print $e['level']; ?></td>
                                                            <?php if($e['is_blocked'] == 1){ ?>
                                                            <td>
                                                                <a href="" class="mrg-top-15 cursor-pointer unblock_admin_modal" id="<?php print $e['unique_id']; ?>">
                                                                    <i class="fa fa-unlock fa-2x"></i>
                                                                </a>
                                                            </td>
                                                            <?php }elseif($e['is_blocked'] == 0){ ?>
                                                            <td>
                                                                <a href="" class="mrg-top-15 cursor-pointer block_admin_modal" id="<?php print $e['unique_id']; ?>">
                                                                    <i class="fa fa-lock fa-2x"></i>
                                                                </a>
                                                            </td>
                                                            <?php } ?>
                                                            <td>
                                                                <a href="" id="<?php print $e['unique_id']; ?>" class="mrg-top-15 cursor-pointer delete_admin_modal" title="Block Account">
                                                                    <i class="fa fa-trash fa-2x"></i>
                                                                </a>
                                                            </td>
                                                        </tr>
                                                    <?php $i++;
                                                    } ?>
                                                </tbody>
                                            </table>


                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal fade zoomInUp" id="delete_admin_modal">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4>Delete Admin?</h4>
                            </div>
                            <form class="delete_admin_form">
                                <div class="modal-body">
                                    <p class="text-danger">By clicking continue, this account will be deleted permanently.</p>
                                </div>
                            </form>
                            <div class="modal-footer no-border">
                                <div class="text-right">
                                    <button class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
                                    <button class="btn btn-primary btn-sm delete_admin_btn" data-dismiss="modal">Continue</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal fade zoomInUp" id="block_admin_modal">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4>Block Admin?</h4>
                            </div>
                            <form class="block_admin_form">
                                <div class="modal-body">
                                    <p class="text-danger">By clicking continue, this account will be blocked..</p>
                                </div>
                            </form>
                            <div class="modal-footer no-border">
                                <div class="text-right">
                                    <button class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
                                    <button class="btn btn-primary btn-sm block_admin_btn" data-dismiss="modal">Continue</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal fade zoomInUp" id="unblock_admin_modal">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4>Block Admin?</h4>
                            </div>
                            <form class="unblock_admin_form">
                                <div class="modal-body">
                                    <p class="text-danger">By clicking continue, this account will be activated.</p>
                                </div>
                            </form>
                            <div class="modal-footer no-border">
                                <div class="text-right">
                                    <button class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
                                    <button class="btn btn-primary btn-sm unblock_admin_btn" data-dismiss="modal">Continue</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Content Wrapper END -->
                <?php require_once('footer.php'); ?>
                <!-- Footer END -->

            </div>
            <!-- Page Container END -->

        </div>
    </div>

    <?php require_once('footer-links.php'); ?>
    <script>
        
        $('.delete_admin_modal').click(function(e) {
            e.preventDefault();
            append_id('delete_admin_id', '.delete_admin_form', '#delete_admin_modal', this)
            $('#delete_admin_modal').modal('toggle');
        });
        $('.block_admin_modal').click(function(e) {
            e.preventDefault();
            append_id('block_admin_id', '.block_admin_form', '#block_admin_modal', this)
            $('#block_admin_modal').modal('toggle');
        });
        $('.unblock_admin_modal').click(function(e) {
            e.preventDefault();
            append_id('unblock_admin_id', '.unblock_admin_form', '#unblock_admin_modal', this)
            $('#unblock_admin_modal').modal('toggle');
        });

        $('.new_admin_btn').click(async function(e) {
            e.preventDefault();
            let new_admin_form = $('.new_admin_form').serializeArray();
            let form_data = set_form_data(new_admin_form);
            // console.log(new_admin_form);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            throwSweetalert(returned, 'admin', 1);
        });
        $('.delete_admin_btn').click(async function(e) {
            e.preventDefault();
            let delete_admin_form = $('.delete_admin_form').serializeArray();
            let form_data = set_form_data(delete_admin_form);
            // console.log(delete_admin_form);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            // console.log(returned);return;
            throwSweetalert(returned, 'admin', 1);
        });
        $('.block_admin_btn').click(async function(e) {
            e.preventDefault();
            let block_admin_form = $('.block_admin_form').serializeArray();
            let form_data = set_form_data(block_admin_form);
            // console.log(block_admin_form);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            // console.log(returned);return;
            throwSweetalert(returned, 'admin', 1);
        });
        $('.unblock_admin_btn').click(async function(e) {
            e.preventDefault();
            let unblock_admin_form = $('.unblock_admin_form').serializeArray();
            let form_data = set_form_data(unblock_admin_form);
            // console.log(unblock_admin_form);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            // console.log(returned);return;
            throwSweetalert(returned, 'admin', 1);
        });
    </script>