<?php

include '../system/sys.php';
include '../system/funcs.php';

if (!isset ($us['id'])) {
        header ('location: /');
        exit;
}
if ($us['level'] < 1) {
        header ('location: /');
        exit;
}

H ('Одобрение регистраций', 'Одобрение регистраций');

if (isset ($_GET['dop'])) {
        
        if (!isset ($_GET['u'])) {
                header ('location: /adm/rega.php');
                exit;
        }
        
        $query = DB :: $dbs -> query ("SELECT * FROM `reg` WHERE (`us`=?)", array ((int) $_GET['u']));
        if ($query -> rowCount () == 0) {
                header ('location: /adm/rega.php');
                exit;
        }
                
        $reg = $query -> fetch ();
        if (!isset ($reg['dop'])) {
                if ($_GET['dop']=='da') {
                        DB :: $dbs -> query ("UPDATE `reg` SET `dop`='da',  `kem`='" . $us['id'] . "' WHERE (`us`='" . $reg['us'] . "')");
                }
                if ($_GET['dop']=='net'){
                        DB :: $dbs -> query ("UPDATE `reg` SET `dop`='net', `kem`='" . $us['id'] . "' WHERE (`us`='" . $reg['us'] . "')");
                }
        }
                
        header ("location: /adm/rega.php");
        
}

$items_per_page = 10;
$items = DB :: $dbs -> querySingle ("SELECT COUNT(*) FROM `reg` WHERE (`dop` IS NULL)");
$pages = ( ( $items - 1 ) / $items_per_page ) + 1;
$page = (int) $_GET['page'];

if ($page < 1)
    $page = 1;

if ($page > $pages)
    $page = $pages;
    
$start = $page * $items_per_page - $items_per_page;

if ($items == 0) {
        echo '<div class="list1">Новых регистраций не было!</div>';
}
else {

        $query = DB :: $dbs -> query ("SELECT * FROM `reg` WHERE (`dop` IS NULL) ORDER BY `id` DESC LIMIT $start, $items_per_page");
        while ($reg = $query -> fetch()) {
            
                $u = DB :: $dbs -> queryFetch ("SELECT * FROM `us` WHERE (`id`=?)", array ($reg['us']));
                
                echo '<div class="list1">';
                echo uNick ($u['id']) . ' [<a href="/adm/ips.php?ip=' . $u['ip'] . '">Проверить по IP</a>]<br/>';
                echo '- <a href="/adm/rega.php?dop=da&u='.$u['id'].'">Одобрить</a>';
                echo ' | ';
                echo ' <a href="/adm/rega.php?dop=net&u='.$u['id'].'">Откл.</a>';
                echo '</div>';

        }

        echo '<div class="navg">' . pages ('/adm/rega') . '</div>';

}

echo '<div class="navg"><a href="/adm">Вернуться</a></div>';

F ();
