<?php
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

if (!isset($_SESSION['username'])) {
    header("location: login");
}
$users = $_SESSION['users'];
?>


<!-- Begin Page Content -->
<div class="container-fluid">

    <div class="d-sm-flex align-items-center justify-content-between mb-4">
        <h1 class="h3 mb-0 text-gray-800">Users</h1>
        <a href="#" class="d-none d-sm-inline-block btn btn-sm btn-primary shadow-sm"><i class="fas fa-download fa-sm text-white-50"></i> Generate Report</a>
    </div>

    <!-- Content Row -->
    <div class="row">

        <!-- Earnings (Monthly) Card Example -->
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="card border-left-primary shadow h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
                                Total Users</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800"><?php echo $_SESSION['countUsers'] ?></div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-user fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Earnings (Monthly) Card Example -->
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="card border-left-success shadow h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-success text-uppercase mb-1">
                                Sermons</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800"><?php echo $_SESSION['countSermon'] ?></div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-book fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Earnings (Monthly) Card Example -->
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="card border-left-info shadow h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-success text-uppercase mb-1">
                                Categories</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800"><?php echo $_SESSION['countServices'] ?></div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-clipboard-list fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Pending Requests Card Example -->
        <div class="col-xl-3 col-md-6 mb-4">
            <div class="card border-left-warning shadow h-100 py-2">
                <div class="card-body">
                    <div class="row no-gutters align-items-center">
                        <div class="col mr-2">
                            <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">
                                Last Login</div>
                            <div class="h5 mb-0 font-weight-bold text-gray-800"><?php echo $_SESSION['user_login'] ?></div>
                        </div>
                        <div class="col-auto">
                            <i class="fas fa-clock fa-2x text-gray-300"></i>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <!-- DataTales Example -->
    <div class="card shadow mb-4">
        <?php
        if (isset($_REQUEST['msg']) && isset($_REQUEST['type'])) {

            if ($_REQUEST['type'] == "error")
                $msg = "<div class='col-lg-6 mb-4'><div class='card bg-danger text-white shadow'><div class='card-body'>" . $_REQUEST['msg'] . "<div class='text-white-50 small'></div></div></div></div>";
            else if ($_REQUEST['type'] == "confirmation")
                $msg = "<div class='col-lg-6 mb-4'><div class='card bg-success text-white shadow'><div class='card-body'>" . $_REQUEST['msg'] . "<div class='text-white-50 small'></div></div></div></div>";

            echo $msg;
        }
        ?>
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">Application Users</h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>ID</th>
                            <th>Name</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Type</th>
                            <th>Created Date</th>
                            <th>Modified date</th>
                            <th>Last Login</th>
                            <th>Activated</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th>ID</th>
                            <th>Name</th>
                            <th>Phone</th>
                            <th>Email</th>
                            <th>Type</th>
                            <th>Created Date</th>
                            <th>Modified date</th>
                            <th>Last Login</th>
                            <th>Activated</th>
                            <th></th>
                        </tr>
                    </tfoot>
                    <tbody>
                        <?php
                        foreach ($users as $user) { ?>
                            <tr>
                                <td><?php echo $user->id ?></td>
                                <td><?php echo $user->full_name ?></td>
                                <td><?php echo $user->phone ?></td>
                                <td><?php echo $user->email ?></td>
                                <td><?php echo $user->user_class ?></td>
                                <td><?php echo $user->created_date ?></td>
                                <td><?php echo $user->modified_date ?></td>
                                <td><?php echo $user->last_login_date ?></td>
                                <td><?php
                                    $stat = "false";
                                    if ($user->activated == 1) {
                                        $stat = "true";
                                    }
                                    echo $stat;
                                    ?></td>
                                <td><a class="btn btn-warning" href="edit_user?user_id=<?php echo $user->id ?>">Edit</a>&nbsp;&nbsp;&nbsp;<?php if ($stat == "false") {
                                                                                                                                                echo '<a class="btn btn-danger" href="activate_user?user_id=' . $user->id . '">Activate</a>';
                                                                                                                                            } else {
                                                                                                                                                echo '<a class="btn btn-danger" href="delete_user?user_id=' . $user->id . '">Deactivate</a>';
                                                                                                                                            } ?></td>
                            </tr>
                        <?php } ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

</div>
<!-- /.container-fluid -->