<?php
$post = DB :: $pdo -> queryFetch("SELECT * FROM `groups_komm` WHERE `id` = ? AND `id_group` = ? AND `id_post` = '0' LIMIT 1;", array(intval($_GET['komm']), $group['id']));
if (isset($user['id']) && (($user['id']==$ank['id'] && $group['d_user'] == 0 && $group['block'] == 0) || $user['id'] == 1 || ($group_user['admin'] > 0 && $group['block'] == 0)) && isset($_GET['dell_komms']))
{require('dell_komms.php');exit;} #Удалить комментры
else if (isset($user['id']) && (($user['id']==$ank['id'] && $group['d_user'] == 0 && $group['block'] == 0) || $user['id'] == 1) && isset($_GET['edit_komms']))
{require('edit_komms.php');exit;} #Изменить  комментры
$title = $l = group :: getName($group); #Тайтл
$lBack = "/groups?group=".$group['id'].""; #Ссылка в профиль
require (CORE."head.php"); #Шапка
$post_ank = profile :: getUser($post['id_user']);

?>

 <div class="app-block">
            <div class="list _l-padd-n">
                <div class="_l-padd">
                  <?php    if (isset($user['id']) && (($user['id']==$ank['id'] && $group['d_user'] == 0) || $user['id'] == 1 || $group_user['admin'] > 0))
{ ?>
                    <div>
                            <a class="toggle-menu-act" onclick="UI.toggleMenu(this);">
                                <span></span>
                            </a>
                            <div class="toggle-menu">
                            <div class="toggle-menu-arrow"><span></span></div>
                            <ul class="toggle-menu-block">
                         <? if (isset($user['id']) && (($user['id']==$ank['id'] && $group['d_user'] == 0) || $user['id'] == 1))
                {  ?> <a href="/groups/?group=<?echo $group['id'];?>&edit_komm=<?echo $post['id'];?>">Редактировать</a> <?}?>
                            <a href="/groups/?group=<?echo $group['id'];?>&dell_komm=<?echo $post['id'];?>">Удалить</a>
                            </ul>
                            </div>
                        </div>
                <?php } ?>
                <div class="list-flex">
            <?if ($post['as_admin'] == 1)
            {?>    <div class="post-l"><?=group :: Avatar($group, 2)?></div>
           
            <?} else {?> 
              <div class="post-l"><?=profile :: userAvatar($post_ank,3)?></div>
            <?}?>
            <div class="post-c">
                <div>
            <? if ($post['as_admin'] == 1)
            {?><span class="_name _font-s"><?=profile :: goPage($post_ank)?></span>
            <?} else {?><span class="_name _font-s"><?=profile :: goPage($post_ank)?></span>
            <?}?>  
                        <br />
            <span><a class="_time" href="/groups/?group=<?echo $group['id'];?>&komm=<?echo $post['id'];?>"> <?=system :: times($post['time']);?></a></span>
                </div>
                </div>
                </div>
                <div>
                    
                <?=group:: Komments($post['id'])?>
                    
                </div>
                                <div>
              
                </div>
                
                </div>



                
                
            </div>
           <!-- </div>-->







<?
$mess_cc = DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `groups_komm` WHERE `id_group` = '".$group['id']."' AND `id_post` = '".$post['id']."'"); #Комментарии 
echo"<div class='list _bg-blue'>Комментарии к записи<span class='_fl-r'>".$mess_cc."</span></div>";








if (isset($user['id']) && $group['block'] == 0)
{
    if (isset($_GET['otvet']) && DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `groups_komm` WHERE `id` = '".intval($_GET['otvet'])."' AND `as_admin` = '0'") > 0)
    {
        $g_p = DB :: $pdo -> queryFetch("SELECT * FROM `groups_komm` WHERE `id` = ? LIMIT 1;", array(intval($_GET['otvet'])));
        $otvet = profile :: getUser($g_p['id_user']);
        if ($user['id'] == $otvet['id'])
        {
            $g_p['id'] = 0;
            $otvet['id'] = 0;
        }
    } else {
        $g_p['id'] = 0;
        $otvet['id'] = 0;
    }
    require('send_komment2.php');
    ?>
    
    
    
    <div>
         	<?if ($otvet['id'] > 0)
                    {
                    ?>
                        <form method="post" data-type="arbour"  action="/groups/?group=<?echo $group['id'];?>&komm=<?echo $post['id'];?>&otvet=<?echo $g_p['id'];?>">
                    <?
                    } else {
                    ?>
                        <form method="post" data-type="arbour"  action="/groups/?group=<?echo $group['id'];?>&komm=<?echo $post['id'];?>">
                    <?
                    }
                 
                    ?>
                <div>
                    <textarea name="komment" class="app-textarea" id="komment" data-id="emoji-block_1" placeholder="Расскажите друзьям что у Вас нового.."></textarea>
                </div>
                             <div class="list _bg-blue">
                    
                    <div class="list-fle">
                        <input class="main-btn" type="submit" name="cfms" value="Отправить">
                    
                   <?if (isset($user['id']) && (($user['id']==$ank['id'] && $group['d_user'] == 0) || $user['id'] == 1 || $group_user['admin'] > 0))
                    {
                    ?>
                        
                                <label class="">
                                    <input type="checkbox" name="as_admin" value="1" /> от имени группы
                                </label>
                          
                    <?
                    }
                    ?>
				<?	   if ($otvet['id'] > 0)
                    {
                    ?>
                        <span style="color: gray;margin: 5px;">
                            Ответ для <?echo profile :: goPage($otvet,folse);?>
                            (<a href="/groups/?group=<?echo $group['id'];?>&komm=<?echo $post['id'];?>">отменить</a>)
                        </span>
                    <?
                    } ?>
             
              
                        <i class="SmileButton" id="SmileButton" style="display: inline;"></i>                       
                    </div>
                    
                </div>
                    
            </form>
        </div>
 
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
       
 
       
    
    
    
    
    <?


}








//Пагинация
if ($mess_cc > 10)
{
    $p = (($_GET['p']) ? intval($_GET['p']) : 1);
    $pagination = new pagination(10, $mess_cc, $p);
    $total_lin = $pagination -> limit;
} else {
    $total_lin = '';
}

// Вывод комментов
$query = DB :: $pdo -> query("SELECT * FROM `groups_komm` WHERE `id_group` = '".$group['id']."' AND `id_post` = '".$post['id']."' ORDER BY `id` DESC ".$total_lin."");
echo '<div class="post-list-all">';
while($r = $query -> fetch())
{
$post_ank = profile :: getUser($r['id_user']);
?>
<div class="list">
  

 <div>
                            <a class="toggle-menu-act" onclick="UI.toggleMenu(this);">
                                <span></span>
                            </a>
                            <div class="toggle-menu">
                            <div class="toggle-menu-arrow"><span></span></div>
                            <ul class="toggle-menu-block">
                            <?  if ($user['id'] != $post_ank['id'] && $r['as_admin'] == 0)
                {  ?><a href="/groups/?group=<?echo $group['id'];?>&komm=<?echo $post['id'];?>&otvet=<?echo $r['id'];?>#otvet">Ответить</a> <?}?>
                      
                         <?  if (isset($user['id']) && (($user['id']==$ank['id'] && $group['d_user'] == 0) || $user['id'] == 1))
                    {    ?>  <a href="/groups/?group=<?echo $group['id'];?>&komm=<?echo $post['id'];?>&edit_komms=<?echo $r['id'];?>">Редактировать</a> <?}?>
                 <a href="/groups/?group=<?echo $group['id'];?>&komm=<?echo $post['id'];?>&dell_komms=<?echo $r['id'];?>">Удалить</a>
                            </ul> 
                          
                            </div>
                        </div>
                       
    <div class="_oh">

            <div class="list-flex">
                <div class="post-l">
                    <? if ($r['as_admin'] == 1)
            {
            ?>
              <?=group :: Avatar($group, 2)?>
            <?
            } else {
            ?>
            <?=profile :: userAvatar($post_ank,3)?>
            <?
            }
            ?>
                    
                    
                    
                    
                    
                    
                
                </div>
                <div class="post-c">
                    <div style="display: block;"><span class="_name">
                         <?
                    if ($r['as_admin'] == 1)
                    {
                    ?>
                  <?=$group['name'];?>
                    <?
                    } else {
                    ?>
                    
                        <?echo profile :: goPage($post_ank);?>
                      
                  <?
                    }
                    ?>
                        
                      
                        
                        
                        
                        
                        </span>
                        <div><span class="_font-m _gray"><?= system:: times($r['time']) ?></span></div>
                    </div>
                </div>
            </div>
        </div>
        <div class="_oh"><span style="vertical-align: sub;">
            
            <?php
                            if ($r['id_post2'] > 0)
                            {
                                $g_pz = DB :: $pdo -> queryFetch("SELECT `id_user` FROM `groups_komm` WHERE `id` = ? LIMIT 1;", array($r['id_post2']));
                                $post_an = profile :: getUser($g_pz['id_user']);
                                ?>
                               <span class="_name">
                                <?echo profile :: goPage($post_an, folse);?>
                                </span> ,
                                <?
                            }
                          ?>
             
         <?=group:: Komments($r['id'])?></span>
        </div>
    </div>

 
    
<?
}
?></div>   </div>

<?
    


// Пагинация
if ($mess_cc > 10)
{
    echo $pagination -> printPages("/groups/?group=".$group['id']."&komm=".$post['id']."&"); 
}

// Если нету комментов 
if($mess_cc == 0){
			echo "<div class=\"_l-padd _center _gray _font-s\">Комментарии к записи отсутствуют.</div>";
		}
//Назад
echo"<div class='app-block'>";
echo system :: touch("/groups/?group=".$group['id']."", system :: icon("arr-l")."Назад");
echo"</div>";

// Низ
require (CORE."foot.php");
