<?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");
}

$messages = $_SESSION['sermons'];
?>


<!-- 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">Sermons</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">Sermons</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>Title</th>
                            <th>Preacher</th>
                            <th>Service</th>
                            <th>Date</th>
                            <th>Uploaded By</th>
                            <!--<th>Updated Date</th>-->
                            <th>Updated By</th>
                            <th></th>
                        </tr>
                    </thead>
                    <tfoot>
                            <th>ID</th>
                            <th>Title</th>
                            <th>Preacher</th>
                            <th>Service</th>
                            <th>Date</th>
                            <th>Uploaded By</th>
                            <!--<th>Updated Date</th>-->
                            <th>Updated By</th>
                            <th></th>
                        </tr>
                    </tfoot>
                    <tbody>
                        <?php foreach ($messages as $message) { ?>
                            <tr>
                                <td><?php echo $message->id; ?></td>
                                <td><?php echo $message->title; ?></td>
                                <td><?php echo $message->preacher; ?></td>
                                <td><?php echo $_SESSION["service".$message->service]; ?></td>
                                <td><?php echo $message->service_date; ?></td>
                                <td><?php echo $message->uploaded_by; ?></td>
                                <td><?php echo $message->updated_by; ?></td>
                                <td><a class="btn btn-warning" href="edit_message?message_id=<?php echo $message->id; ?>">Edit</a>
                                &nbsp;<a class="btn btn-danger" href="delete_message?message_id=<?php echo $message->id; ?>">Delete</a>
                                &nbsp;<a class="btn btn-danger" href="archive_message?message_id=<?php echo $message->id; ?>">Archive</a></td>
                            </tr>
                        <?php } ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>

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