<?php
require_once "common/header.php";
require_once "include/db_handler.php";
?>

<body>

<div class="container-fluid">
    <div class="row">
        <?php
        require_once "common/sidebar.php";
        ?>
        <div class="right-column">
            <?php
            require_once "common/navbar.php";
            ?>
            <main class="main-content p-5" role="main">

                <div class="row mb-5">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-mailbox">
                                <div class="row mx-0">

                                    <?php
                                    $query = "SELECT *, UNIX_TIMESTAMP(dateCreated) as dateCreated FROM tbl_messages WHERE recipient = 'info@womankenya.com'";
                                    $response = $db->getAllMessages($query);
                                    ?>

                                    <div class="col-lg-12">
                                        <div class="mailbox-container mailbox-email-list">
                                            <div class="mailbox-controls clearfix">
                                                <div class="email-pager-top">
                                                    <div class="email-pager-container">
                                                        <div class="btn-group" role="group"
                                                             aria-label="Previous or Next Page">
                                                            <button type="button"
                                                                    class="btn btn-primary email-list-previous"
                                                                    data-toggle="tooltip" title="Previous">
                                                                <i class="batch-icon batch-icon-arrow-left"></i>
                                                            </button>
                                                            <button type="button"
                                                                    class="btn btn-primary email-list-next"
                                                                    data-toggle="tooltip" title="Next">
                                                                <i class="batch-icon batch-icon-arrow-right"></i>
                                                            </button>
                                                        </div>
                                                    </div>

                                                </div>
                                            </div>
                                            <div class="mailbox-mail-list table-responsive">
                                                <table class="table table-hover">

                                                    <?php foreach ($response as $mail) :
                                                        $status = $mail['status'];
                                                        if ($status == "read") {
                                                            ?>
                                                            <tr class="" data-email-id="3"
                                                                data-email-url="mail_message.php?id=<?php echo $mail['id']; ?>">
                                                                <td class="email-checkbox">
                                                                    <div class="custom-control custom-checkbox email-item-checkbox">
                                                                        <input type="checkbox"
                                                                               class="custom-control-input">
                                                                        <label class="custom-control-label"><span
                                                                                    class="sr-only">(checkbox)</span></label>
                                                                    </div>
                                                                </td>
                                                                <td class="email-star">
																<span class="email-star-status">
																	<i class="batch-icon batch-icon-star-alt email-important"
                                                                       data-toggle="tooltip" title="Important Mail"></i>
																</span>
                                                                </td>
                                                                <td class="email-sender">
                                                                    <?php echo $mail['name']; ?>
                                                                </td>
                                                                <td class="email-subject">
                                                                    <?php echo $mail['subject']; ?>
                                                                </td>
                                                                <td class="email-datetime">
                                                                    <?php $db->timeAgo($mail['dateCreated']); ?>
                                                                </td>
                                                            </tr>
                                                            <?php
                                                        } elseif ($status == "unread") {
                                                            ?>
                                                            <tr class="email-status-unread" data-email-id="3"
                                                                data-email-url="mail_message.php?id=<?php echo $mail['id']; ?>">
                                                                <td class="email-checkbox">
                                                                    <div class="custom-control custom-checkbox email-item-checkbox">
                                                                        <input type="checkbox"
                                                                               class="custom-control-input">
                                                                        <label class="custom-control-label"><span
                                                                                    class="sr-only">(checkbox)</span></label>
                                                                    </div>
                                                                </td>
                                                                <td class="email-star">
																<span class="email-star-status">
																	<i class="batch-icon batch-icon-star-alt email-important"
                                                                       data-toggle="tooltip" title="Important Mail"></i>
																</span>
                                                                </td>
                                                                <td class="email-sender">
                                                                    <?php echo $mail['name']; ?>
                                                                </td>
                                                                <td class="email-subject">
                                                                    <?php echo $mail['subject']; ?>
                                                                </td>
                                                                <td class="email-datetime">
                                                                    <?php $db->timeAgo($mail['dateCreated']); ?>
                                                                </td>
                                                            </tr>
                                                            <?php
                                                        }
                                                        ?>

                                                    <?php endforeach; ?>

                                                    <tr class="empty-list">
                                                        <td colspan="5">You currently have no emails.</td>
                                                    </tr>
                                                </table>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </main>
        </div>
    </div>
</div>
<?php
require_once "modals/add_article.php";
require_once "modals/logout.php";
require_once "modals/add_category.php";
require_once "common/footer.php";
?>

