<?php 
global $myUser;
if(!$myUser->can('log','read')) throw new Exception("Permissions insuffisantes",403);
$categories = array();
foreach(Log::staticQuery('SELECT DISTINCT category FROM {{table}} ORDER BY category',array(),true) as $category)
	$categories[$category->category] = $category->category; 
?>
<div class="row">
	<div class="col-md-12">
		<br>
		<h3>Logs</h3>
		<hr/>

		<div class="row">
			<div class="col-md-12">
				<select id="filters" data-type="filter" data-label="Recherche" data-function="search_log">
				    <option value="category" data-filter-type="dictionnary" data-filter-source='<?php echo json_encode($categories); ?>'>Catégorie</option>
				    <option value="created" data-filter-type="date">Date</option>
				    <option value="ip" data-filter-type="text">IP</option>
				    <option value="creator" data-filter-type="user">Auteur</option>
				</select>
			</div>
		</div>
		<br/>
		<div class="row">
			<div class="col-md-12">
				<table id="logs" class="table table-striped">
					<thead>
						<tr>
							<th data-sortable="created">Date</th>
							<th data-sortable="category">Catégorie</th>
							<th data-sortable="label" class="log-col">Libellé</th>
							<th data-sortable="creator">Utilisateur</th>
							<th data-sortable="ip">Ip</th>
						</tr>
					</thead>
					<tbody>
						<tr data-id="{{id}}" class="hidden">
							<td>{{created}}</td>
							<td>{{category}}</td>
							<td class="log-col">{{{label}}}</td>
							<td>{{creator}}</td>
							<td>{{ip}}</td>
						</tr>
					</tbody>
				</table>

				<ul class="pagination justify-content-center">
				    <li class="page-item hidden" data-value="{{value}}" title="Voir la page {{label}}" onclick="$(this).parent().find('li').removeClass('active');$(this).addClass('active');search_log()">
				        <a class="page-link" href="#">{{label}}</a>
				    </li>
				</ul>
			</div>
		</div>
	</div>
</div>