<?php
/**
 * @version 7.1
 */
?>


    <div class="table-responsive">
        <table class="table table-striped table-hover">
            <caption>
                <strong><?php echo $this->paginator->getPages()->totalItemCount; ?></strong> <?php echo $this->_('online users found.'); ?>

                <?php if ($this->paginator->getPages()->totalItemCount) { ?>
                    <?php echo $this->_('Showing results'); ?>
                    <strong><?php echo $this->paginator->getPages()->firstItemNumber; ?></strong>
                    <?php echo $this->_('to'); ?>
                    <strong><?php echo $this->paginator->getPages()->lastItemNumber; ?></strong>
                <?php } ?>
            </caption>
            <?php if ($this->paginator->getPages()->totalItemCount) { ?>
                <thead>
                <tr>
                    <th class="size-small"><?php echo $this->_('User / IP'); ?></th>
                    <th><?php echo $this->_('Active Page'); ?></th>
                    <th class="size-medium"><?php echo $this->_('Browser'); ?></th>
                    <th class="size-mini"><?php echo $this->_('Language'); ?></th>
                    <th class="size-mini"><?php echo $this->_('Session Duration'); ?></th>
                </tr>
                </thead>
            <?php } ?>
            <tbody>
            <?php
            /** @var \Cube\Db\Table\Row $stat */
            foreach ($this->paginator as $stat) {
                $link = $this->url($stat['request_uri'], null, false, null, false);
                $user = $stat->findParentRow('\Ppb\Db\Table\Users');
                ?>
                <tr>
                    <td>
                        <div><?php echo $this->fieldDisplay($user, $user['username'], '<em>' . $this->_('Guest') . '</em>'); ?></div>
                        <div>
                            <small>
                                <abbr
                                    title="<?php echo @gethostbyaddr($stat['remote_addr']); ?>"><?php echo $stat['remote_addr']; ?></abbr>
                            </small>
                        </div>
                    </td>
                    <td>
                        <div>
                            <a href="<?php echo $link; ?>" target="_blank">
                                <?php echo $stat['request_uri']; ?>
                            </a>
                        </div>
                        <div>
                            <small><?php echo $stat['page_title']; ?></small>
                        </div>

                        <?php if (!empty($stat['http_referrer'])) { ?>
                            <div>
                                <small><em><?php echo $stat['http_referrer']; ?></em></small>
                            </div>
                        <?php } ?>
                    </td>
                    <td>
                        <small>
                            <abbr
                                title="<?php echo $stat['http_user_agent']; ?>"><?php echo substr($stat['http_user_agent'], 0, 60) . ' ... '; ?></abbr>
                        </small>
                    </td>
                    <td>
                        <small>
                            <?php echo $stat['http_accept_language']; ?>
                        </small>
                    </td>
                    <td>
                        <?php
                        $start = new \DateTime($stat['created_at']);
                        $updatedAt = ($stat['updated_at'] == $stat['created_at']) ? date('Y-m-d H:i:s', time()) : $stat['updated_at'];

                        $interval = $start->diff(new \DateTime($updatedAt));
                        echo $interval->format('%i:%S');
                        ?>
                    </td>
                </tr>
            <?php } ?>
            </tbody>
        </table>
    </div>


<?php echo $this->pagination($this->paginator, 'sliding', 'partials/pagination.phtml'); ?>