<?
 
?>
<div class="app-block">
 <?
if (isset($_GET['add_files']))
{
    require('add_files2.php');
    exit;
}
else if (isset($_GET['add_photos']))
{
    require('add_photos2.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 `id_blog` = '".$note['id']."'") > 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."/template/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 `id_blog` = '".$note['id']."' LIMIT 1");
    header("Location: /blog/?note=".$note['id']."&edit");
    exit;
}
//Редктор 

	if(isset($_POST['cfms'])) {
	    $message = system :: check($_POST['message']);
	    $msg_str = system :: utf_strlen($message);
		if($msg_str >= 3) {
			if($msg_str <= 1000) {	
			

			

				if($note['text'] != $message) {
					DB :: $pdo -> query("UPDATE `blog` SET  `text` =?  WHERE `id` = ?;", [$message, $note['id']]);
					
				}	
				system :: redirect("Запись успешно отредактирована.", "/blog?note={$note['id']}");
			} else { $errMsg = "Сообщение превышает 10000 знаков."; }
		} else { $errMsg = "Пустое сообщение."; }
	}
	system :: show($errMsg);
?>


        <div>
            <form method="post" action="/blog/?note=<?echo $note['id'];?>&edit">
                <div>
                    <textarea name="message" class="app-textarea" id="message" data-id="emoji-block_1" placeholder="Расскажите друзьям что у Вас нового.."><?=emoji :: decode($note['text'])?></textarea>
                </div>
             <?
          if (DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `blog_files` WHERE `id_blog` = '".$note['id']."' AND `time` > '0'") > 0)
            {
            ?>
                <div class="list list_blog10">
                    <?
                   $query_f = DB :: $pdo -> query("SELECT * FROM `blog_files` WHERE `id_blog` = '".$note['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/?note=<?echo $note['id'];?>&edit&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/?note=<?echo $note['id'];?>&edit&amp;add_files" style="margin-left: 15px;"><i class="fa fa-paperclip fa-2x"></i>
                   
                </a>
              <a href="/blog/?note=<?echo $note['id'];?>&edit&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>
        








<?
echo system :: touch("/blog/?note=".$note['id']."", system :: icon("arr-l")."Назад");
require (CORE."foot.php");
?>