<?

if (isset($_POST['cfms']))
{
    if (!isset($_POST['komment']) || $_POST['komment']==NULL)
    {
    	$error = "Вы должны что-то написать!";
    } else {
        $komm = system :: check($_POST['komment']);
    	if (DB :: $pdo -> query("INSERT INTO `blog_comments` (`id_user`, `id_note`, `time`, `message`, `id_post`) VALUES (?, ?, ?, ?, ?);", array($user['id'], $note['id'], time(), $komm, $g_p['id'])))
        {
            
 //-------извещения-------//
            if ($otvet['id'] == 0 && $user['id'] != $ank['id'])
            {
                notif::init()->blog(['id_user' => $ank['id'],   'id_last' => $user['id'], 'id_obj' => $note['id'], 'notices_text' =>$komm]);
    		   // DB :: $pdo -> query("INSERT INTO `notices` (`id_user`, `id_ank`, `text`, `type`, `read`, `time`) VALUES (?, ?, ?, ?, ?, ?);", array($user['id'], $ank['id'], $o, 0, 0, time()));
                DB :: $pdo -> query("UPDATE `users` SET `count_new_notice` = `count_new_notice`+1 WHERE `id` = '".$ank['id']."' LIMIT 1");
            }
            if ($otvet['id'] > 0)
            {
                if ($otvet['id'] != $ank['id'])
                {
                    notif::init()->blog_otvet(['id_user' => $otvet['id'],   'id_last' => $user['id'], 'id_obj' => $note['id'], 'notices_text' =>$komm]);
                     DB :: $pdo -> query("UPDATE `users` SET `count_new_notice` = `count_new_notice`+1 WHERE `id` = '".$otvet['id']."' LIMIT 1");
                }
               if ($user['id'] != $ank['id'])
                {
                     notif::init()->blog_otvet(['id_user' => $ank['id'],   'id_last' => $user['id'], 'id_obj' => $note['id'], 'notices_text' =>$komm]);
                  
                DB :: $pdo -> query("UPDATE `users` SET `count_new_notice` = `count_new_notice`+1 WHERE `id` = '".$ank['id']."' LIMIT 1");
                }
            }
            
            
         
        
            system :: redirect("Сообщение успешно добавлено.", "/blog/?note=".$note['id']."");
    	} else {
    		$error = "Неизвестная ошибка.!";
    	}
    }
}
if (isset($error))
{
?>
    <div class="list _gray _font-s _center"><?echo stripcslashes(htmlspecialchars($error));?></div>
<?
}
?>