<div class="section">
    <div class="row">
        <div class="small-6 columns">
            <h2><i class="fa fa-envelope"></i> Messaging</h2>
        </div>
        <div class="small-6 columns right">
            <ul class="button-group radius right">
                <li><a href="#" data-reveal-id="newMessage" class="button success"><i class="fa fa-plus"></i> New Message</a></li>
            </ul>
        </div>
    </div>
    <div class="row">
        <div class="small-12 columns">
            <?php
                if(count($this->messages->systemMessages) > 0)
                {
                    echo "
                        <table width='100%'>
                            <thead>
                                <tr>
                                    <th>Post Date</th>
                                    <th>Message</th>
                                    <th>Expiration Date (EOD)</th>
                                    <th>Options</th>
                                </tr>
                            </thead>
                            <tbody>
                    ";

                    foreach($this->messages->systemMessages as $message)
                    {

                        $date = new DateTime();
                        $date->setTimestamp($message['expireDate']);

                        echo "

                            <tr>
                                <td>".$message['postDate']."</td>
                                <td>".$message['message']."</td>
                                <td>".$date->format('l, F jS Y')."</td>
                                <td><a href='".$this->link(array('messages','edit',$message['id']))."'>Edit</a></td>
                            </tr>

                        ";

                    }
                    echo "</tbody></table>";
                }
                else
                {
                    echo "<div class='small-12 columns text-center'>- No system messages -</div>";
                }
            ?>
        </div>
    </div>
    <div class="row">
        <div class="small-12 columns">
            <h2><i class="fa fa-envelope-square"></i> Account Messaging</h2>
        </div>
    </div>
    <div class="row">
        <div class="small-12 columns">
            <?php

            if(count($this->messages->supervisorMessages) > 0)
            {
                echo "
                        <table width='100%'>
                            <thead>
                                <tr>
                                    <th>Post Date</th>
                                    <th>Sent to</th>
                                    <th>Message</th>
                                    <th>Expiration Date (EOD)</th>
                                    <th>Read on</th>
                                    <th>Options</th>
                                </tr>
                            </thead>
                            <tbody>
                    ";
                foreach($this->messages->supervisorMessages as $message)
                {
                    $date = new DateTime();
                    $expireDate = $date->setTimestamp($message['expireDate'])->format('l, F jS Y');
                    $postDate = $date->setTimestamp($message['postDate'])->format('l, F jS Y');

                    $user = new userModel();
                    $account = $user->userInfo($message['userId']);

                    echo "

                            <tr>
                                <td>$postDate</td>
                                <td>".$account['lastName'].", ".$account['firstName']."</td>
                                <td>".$message['message']."</td>
                                <td>$expireDate</td>
                                <td>".$message['reviewDate']."</td>
                                <td><a href='".$this->link(array('messages','deleteprivate',$message['id']))."'>Delete</a></td>
                            </tr>

                        ";
                }
                echo "</tbody></table>";
            }
            else
            {
                echo "<div class='small-12 columns text-center'>- No system messages -</div>";
            }

            ?>
        </div>
    </div>
</div>

<div id="newMessage" class="reveal-modal small" data-reveal aria-labelledby="New Message" aria-hidden="true" role="dialog">
    <h2 id="modalTitle"><i class="fa fa-plus"></i> New Message</h2>
    <?php echo $this->form; ?>
    <a class="close-reveal-modal" aria-label="Close">&#215;</a>
</div>