<?
if (isset($_GET['note']) && DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `blog` WHERE `id` = '".intval($_GET['note'])."'") > 0)
{require('inc/note.php');exit;}

$title = $l= "Блог"; #Тайтл
 
require (CORE."head.php");
require('inc/inc.php');

if (isset($_GET['id']))
{
    $id = (int)abs($_GET['id']);
    $ank = profile :: getUser($id);
}
if (!isset($_GET['id']) || !isset($ank) || $ank['id'] <= 0)
{
    ?>
    <div class="list _gray _font-s _center">Пользователь не найден!</div>
    <?
    require (CORE."foot.php");
    exit;
}
if (isset($user['id']) && $user['id'] == $ank['id'])
{
    if (isset($_GET['add_files']))
    {
        require('inc/add_files.php');
        exit;
    }
    else if (isset($_GET['add_photos']))
    {
        require('inc/add_photos.php');
        exit;
    }
    else if (isset($_GET['dell_file']) && DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `blog_files` WHERE `id` = '".intval($_GET['dell_file'])."' AND `id_user` = '".$user['id']."' AND `time` = '0'") > 0)
    {
        if (is_file("".FILES_PATH."/blog_files/".intval($_GET['dell_file'])."_m.jpg"))
        {
            unlink("".FILES_PATH."/blog_files/".intval($_GET['dell_file'])."_m.jpg");
        }
        if (is_file("".FILES_PATH."/blog_files/".intval($_GET['dell_file']).".jpg"))
        {
            unlink("".FILES_PATH."/blog_files/".intval($_GET['dell_file']).".jpg");
        }
        DB :: $pdo -> query("DELETE FROM `blog_files` WHERE `id` = '".intval($_GET['dell_file'])."' AND `id_user` = '".$user['id']."' AND `time` = '0' LIMIT 1");
        header("Location: /blog/?id=".$ank['id']."");
        exit;
    }
    require('inc/add_blog.php');
    ?>


    <div class="app-block">
        <div>
            <form method="post" action="/blog/?id=<?echo $ank['id'];?>">
                <div>
                    <textarea name="message" class="app-textarea" id="message" data-id="emoji-block_1" placeholder="Расскажите друзьям что у Вас нового.."></textarea>
                </div>
             <?
            if (DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `blog_files` WHERE `id_user` = '".$user['id']."' AND `time` = '0'") > 0)
            {
            ?>
                <div class="list_blog10">
                    <?
                    $query_f = DB :: $pdo -> query("SELECT * FROM `blog_files` WHERE `id_user` = '".$user['id']."' AND `time` = '0' ORDER BY `id` DESC");
                    while($r_f = $query_f -> fetch())
                    {
                    ?>
                        <div class="list_blog11">
                            <img class="list_blog12 list_blog18" src="<?echo "".FILES_SERVER."/blog_files/".$r_f['id']."_m.jpg";?>" alt="*" />
                            <a class="list_blog13" href="/blog/?id=<?echo $ank['id'];?>&dell_file=<?echo $r_f['id'];?>">
                                <i class="list_blog14"></i>
                            </a>
                        </div>
                    <?
                    }
                    ?>
                </div>
            <?
            }
            ?>
                <div class="list _bg-blue">
                    
                    <div class="list-fle">
                        <input class="main-btn" type="submit" name="cfms" value="Создать запись" />
                       <a href="/blog/?id=<?echo $ank['id'];?>&amp;add_files" style="margin-left: 15px;"><i class="fa fa-paperclip fa-2x"></i>
                   
                </a>
              <a href="/blog/?id=<?echo $ank['id'];?>&amp;add_photos" style="margin-left: 15px;"><i class="fa fa-picture-o fa-2x"></i></a>
              
                        <?=emoji :: Smiles("emoji-block_1","message")?>
                       
                    </div>
                    
                </div>
                    
            </form>
        </div>
        </div>
           
      
    <?
}
$total = DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `blog` WHERE `id_user` = '".$ank['id']."'");
if ($total == 0)
{
?>
    <div class="app-block"><div class="list _gray _font-s _center">Записи в блоге отсутствуют!</div></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 `blog` WHERE `id_user` = '".$ank['id']."' ORDER BY `id` DESC ".$total_lin."");
    while($gpp = $query -> fetch())
    {
    $post_cc = DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `blog_comments` WHERE `id_note` = '".$gpp['id']."'");
    ?>   <div class="app-container">
      <div class="app-user--block">
        <div class="app-user-b_top">
          <div class="app-user-b_uavatar">
            <span class="circle-photo"> <?=profile::userAvatar($ank, 4)?> </span>
          </div>

          <div class="app-user-b_lef">
            <div class="app-user-b_username">
              <a href="" title=""><?=profile::ico($ank).profile::getFullName($ank)?>  <?=profile::vermini($ank)?></a>
            </div>
            <div class="app-user-b_date"><?=system::times($gpp['time'])?></div>
          </div>
        </div>

        <div class="app-user-b_content">
       <?= Emoji :: Text($gpp['text']); ?>
	   <?
	    if (DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `blog_files` WHERE `id_blog` = '".$gpp['id']."'") > 0)
                {
                ?>
                    <div class="list_blog39">
                        <?
                        $query_f = DB :: $pdo -> query("SELECT * FROM `blog_files` WHERE `id_blog` = '".$gpp['id']."' ORDER BY `id` DESC");
                        while($r_f = $query_f -> fetch())
                        {
                        ?>
                         <div class="llq_pdq--291">
                                <a href="/blog_files/<?echo $r_f['id'];?>.jpg">
                                    <img class="liq-pdq--891" src="<?echo "".FILES_SERVER."/blog_files/".$r_f['id']."_m.jpg";?>" alt="*" />
                                </a>
                            </div>
                        <?
                        }
                        ?>
                    </div>
                <?
                }
	   ?>
	  
        </div>
      </div>
     
      <div class="app-user-b_bot">
          
        <a class="app-link_spo" href="/blog/?note=<?=$gpp['id']?>" title="Комментировать">Комментировать </a> <span style="color: #666b7b;padding: 5px;background: #e2e2e2;text-align: center;border-radius: 3px;"><?=$post_cc?></span>

        
      </div>
    </div>
    <?
    }
    if ($total > 10)
    {
        echo $pagination -> printPages("/blog/?id=".$ank['id']."&"); 
    }
}
?>
<div class="app-block">
<?
echo system :: back(profile :: getLink($ank), "Профиль");
?>
</div>
<?
require (CORE."foot.php");
?>