<?
/*
if (isset($ID) && $level == 4 && !isset($_GET['admin'])) {
  $ank = $sql -> fetch("SELECT * FROM `users` WHERE `id` = '$ID' LIMIT 1");
}

if (!isset($ank['id']) && isset($user) || $level < 3) {
  $ank = $user;
}
*/

if (isset($ID)) {
  $ank = $sql -> fetch("SELECT * FROM `users` WHERE `id` = '$ID' LIMIT 1");
}

if (!isset($ank['id']) && isset($user)) {
 $ank = $user;
} else {
  header('Location: /index.php');
  exit;
}

$system['title'] = 'История входов ' . ($ank['id'] != $user['id'] ? login($ank['id']) : '');
require SYS . 'header.php';

$type = array('cookie' => 'Cookie', 'login' => 'ввод Email и Пароля', 'recovery' => ' восстановление доступа');

$k_post = $sql -> selectCount("SELECT COUNT(*) FROM `users_log` WHERE `id_user` = '$ank[id]'");

if ($k_post == 0) {
  ?>
  <div class="alert" style="margin: 2px;">Список авторизаций пуст</div>
  <?
} else {
  $k_page = k_page($k_post, $system['page_str']);
  $page = page($k_page);
  $start =  $system['page_str'] * $page -  $system['page_str'];

  $array = $sql -> select("SELECT * FROM `users_log` WHERE `id_user` = '$ank[id]' ORDER BY `time` DESC LIMIT $start, $system[page_str]");

  foreach ($array AS $post) {
    $num++;
    ?>
    
    <div class="<?= ($num % 2 ? "nav1" : "nav2")?>">
      <span class="ank_n">Время входа:</span> <span class="ank_d"><?= vremja($post['time'])?></span><br />
      <span class="ank_n">Браузер:</span> <span class="ank_d"><?= text($post['ua'])?></span><br />
      <span class="ank_n">IP адрес:</span> <span class="ank_d"><?= long2ip($post['ip'])?></span><br />
      <span class="ank_n">Тип авторизации:</span> <span class="ank_d"><?= $type[$post['type']]?></span><br />
    </div>
    <?
  }

  if ($k_page > 1) { 
    str('?func=' . $func . '&amp;', $k_page, $page);
  }
}
?>