<?php
$this->css($this->assetModule('admin/admin.css'));
$this->jQuery();
//$this->js($this->assetModule('script/system-msg.js', 'system'));
?>
<ul class="nav nav-pills bg-light mb-3 p-3">
    <li class="nav-item">
        <a class="nav-link active" href="<?php echo $this->url('', ['controller' => 'audit', 'action' => 'index']); ?>"
           title="<?php echo _a('Audit'); ?>"><?php echo _a('Audit'); ?></a>
    </li>
    <li class="nav-item">
        <a class="nav-link disabled" href="#" title="<?php echo _a('Mailing'); ?>"><?php echo _a('Mailing'); ?></a>
    </li>
</ul>
<h2 class="page-header"><?php echo _a('Audit list') ?></h2>
<div class="table-responsive">
    <table class="table table-striped table-hover table-sm">
        <thead>
        <tr>
            <th width="15%"><?php echo _a('time') ?></th>
            <th width="2%"><?php echo _a('User ID') ?></th>
            <th width="5%"><?php echo _a('IP') ?></th>
            <th width="2%">`section`</th>
            <th width="8%">`module`</th>
            <th width="8%">`controller`</th>
            <th width="8%">`action`</th>
            <th width="2%">`method`</th>
            <th width="30%"><?php echo _a('Message') ?></th>
            <th><?php echo _a('Extra information') ?></th>
        </tr>
        </thead>
        <?php foreach ($items as $row) { ?>
            <tr>
                <td><?php echo _date($row['time']); ?></td>
                <td><?php echo $row['user']; ?></td>
                <td><?php echo $row['ip']; ?></td>
                <td><?php echo $row['section']; ?></td>
                <td><?php echo $row['module']; ?></td>
                <td><?php echo $row['controller']; ?></td>
                <td><?php echo $row['action']; ?></td>
                <td><?php echo $row['method']; ?></td>
                <td>
                    <span title="<?php echo _escape($row['message']); ?>"><?php echo _escape(substr($row['message'], 0, 50)); ?></span>
                </td>
                <td>
                    <!-- Button trigger modal -->
                    <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#auditModal-<?php echo $row['id']; ?>">
                        <?php _e('View'); ?>
                    </button>
                    <!-- Modal -->
                    <div class="modal fade" id="auditModal-<?php echo $row['id']; ?>" tabindex="-1" role="dialog" aria-labelledby="auditModalLabel-<?php echo $row['id']; ?>" aria-hidden="true">
                        <div class="modal-dialog modal-lg" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="auditModalLabel-<?php echo $row['id']; ?>"><?php echo _a('View') ?></h5>
                                    <button type="button" class="close" data-dismiss="modal" aria-label="<?php echo _a('Close') ?>">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                                <div class="modal-body">
                                    <div class="clearfix">
                                        <h5 class="mb-3"><?php echo _a('Message') ?></h5>
                                        <div style="text-align: left; direction: ltr" class="clearfix">
                                            <pre>
                                                <?php echo $row['message']; ?>
                                            </pre>
                                        </div>
                                    </div>
                                    <hr />
                                    <div class="clearfix">
                                        <h5 class="mb-3 mt-3"><?php echo _a('Extra information') ?></h5>
                                        <div style="text-align: left; direction: ltr" class="clearfix">
                                            <pre>
                                                <?php echo $row['extra']; ?>
                                            </pre>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        <?php } ?>
    </table>
</div>
<?php echo $this->paginationControl($paginator, 'Sliding', 'paginator.phtml'); ?>
<div style="padding: 10px">
    <form method='GET'>
        <div class="form-group">
            <label class="col-md-2 col-form-label text-right"><?php echo _a('Count of items to display: '); ?></label>
            <div class="col-md-1">
                <select id='audit-count' class="form-control"
                        audit-url='<?php echo $this->url('admin', ['controller' => 'audit', 'count' => '__COUNT__']) ?>'>
                    <option value='10' <?php echo(!isset($count) or (10 === $count) ? 'selected' : '') ?>><?php echo _a('10') ?></option>
                    <option value='20' <?php echo(20 === $count ? 'selected' : '') ?>><?php echo _a('20') ?></option>
                    <option value='50' <?php echo(50 === $count ? 'selected' : '') ?>><?php echo _a('50') ?></option>
                </select>
            </div>
        </div>
    </form>
</div>
<script>
    (function ($) {
        $("#audit-count").change(function () {
            var $this = $(this);
            location.href = $this.attr('audit-url').replace('__COUNT__', $this.val());
        })
    })(jQuery)
</script>