<?
$id = (int)abs($_GET['id']);
$ank = profile :: getUser($id);
$title = "Группы";
$l = "Группы";
$back = system :: back(profile :: getLink($ank), "Профиль");
require (CORE."head.php");
require('inc.php');
echo '<div class="app-block">';
$total = DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `groups_users` WHERE `id_user` = '".$ank['id']."'");
if ($total == 0)
{
?>
    <div class="list _gray _font-s _center">Группы не найдены!</div>
<?
} else {
    if ($total > 10)
    {
        $p = (($_GET['p']) ? intval($_GET['p']) : 1);
        $pagination = new pagination(10, $total, $p);
        $total_lin = $pagination -> limit;
    } else {
        $total_lin = '';
    }
    $query = DB :: $pdo -> query("SELECT * FROM `groups_users` WHERE `id_user` = '".$ank['id']."' ORDER BY `id` DESC ".$total_lin."");
    while($gpp = $query -> fetch())
    {
    $group = DB :: $pdo -> queryFetch("SELECT * FROM `groups` WHERE `id` = ? LIMIT 1;", array($gpp['id_group']));
    $k_pc = DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `groups_users` WHERE `id_group` = '".$group['id']."'");
     echo system :: touch("/groups/?group={$group['id']}","
                <div class=\"post-l\">
                  ".group :: Avatar($group,0)."
                </div>
                <div class=\"post-c\">
                    
                    <div>".group :: getName($group)."</div>
                    <div class=\"_gray\">участников: {$k_pc}</div>

                </div>
                ");
    

    }
    if ($total > 10)
    {
        echo $pagination -> printPages("/groups/?"); 
    }
}
if (isset($user['id']) && $user['id'] == $ank['id'])
{
    ?>
    <div class="touch"><a href="/groups/?add_group" class="touch-cont _oh">
                 Создать группу
                </a></div>
   
    <?
}
echo $back;
require (CORE."foot.php");
?>