<?php


$cu = $this->isLogedin();
$page = @$_GET["page"] ? $_GET["page"] : 1;
$page = $page - 1;
$limit = 10;
$data = $this->getUsers($limit, $limit * $page);
$users = $data['users'];
$_SESSION["page"] = $page;
if ($message = @$_SESSION["message"]) {
    if ($message["type"] == "error") {
        $mclass = "alert-danger";
        $mtitle = "Error!!";
    }else{
        $mclass = "alert-success";
        $mtitle = "Success!!";
    }
    ?>
    <div class="alert alert-block <?php echo $mclass ?> fade in">
        <button type="button" class="close close-sm" data-dismiss="alert">
            <i class="fa fa-times"></i>
        </button>
        <h4><?php echo $mtitle ?></h4>
        <?php
        echo $message["message"];
        unset($_SESSION["message"])
        ?>
    </div>
<?php } ?>

<div class="col-sm-12 users">
    <section class="panel">
        <header class="panel-heading">
            Users Manager 
        </header>
        <div class="panel-body">
            <div class="panel">
                <a class="btn btn-success" href="index.php?view=edituser" data-toggle="modal"><i class="fa fa-plus"></i> Add </a>

            </div>
                <table class="table table-hover table-bordered">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>Name</th>
                            <th>Email</th>
                            <th>Username</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($users as $user) : ?>
                            <tr>
                                <td><?php echo $user["id"] ?></td>
                                <td><?php echo $user["name"] ?></td>
                                <td><?php echo $user["email"] ?></td>
                                <td><?php echo $user["username"] ?></td>
                                <td>
                                    <a class="btn btn-success" href="index.php?view=edituser&id=<?php echo $user["id"] ?>" data-toggle="modal">
                                        <i class="fa fa-cog"></i> Edit
                                    </a>
                                    
                                    <?php if($cu["id"] != $user["id"]): ?>
                                    
                                    <button class="btn-delete btn btn-danger" value="<?php echo $user['id'] ?>">
                                        <i class="fa fa-times"></i> Delete! 
                                    </button>
                                    
                                    <?php endif?>
                                    
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
        </div>
    </section>
</div>
   
   <form id="submitForm" action="" method="POST">
         <input id="did" type="hidden" name="did" value="">
   </form>

<script type="text/javascript">

jQuery(document).ready(function() {
	initUsersList();
});
            
            </script>