<?
if (isset($_POST['cfms']))
{
    if (!isset($_POST['komment']) || $_POST['komment']==NULL)
    {
    	$errMsg = "Вы должны что-то написать!";
    } else {
        $komm = system :: check($_POST['komment']);
        if (isset($_POST['as_admin']) && is_numeric($_POST['as_admin']) && $_POST['as_admin']==1 && (($user['id']==$ank['id'] && $group['d_user'] == 0) || $user['id'] == 1 || $group_user['admin'] > 0))
        {
            $as_admin = 1;
        } else {
            $as_admin = 0;
        }
    	if (DB :: $pdo -> query("INSERT INTO `groups_komm` (`id_user`, `id_group`, `as_admin`, `post`, `time`) VALUES (?, ?, ?, ?, ?);", array($user['id'], $group['id'], $as_admin, $komm, time())))
        {
            $last_id = DB :: $pdo -> lastInsertId();
						$id = DB :: $pdo -> lastInsertId();
			#------------NEW EVENTS------------#
			$EventsData = [
				'id_user' => $user['id'],
				'type' => 'groups',
				'id_type' => $last_id,
				'data' => $group['id']
			];
			Events::add($EventsData);
			#------------NEW EVENTS------------#
            if (DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `groups_files` WHERE `id_user` = '".$user['id']."' AND `id_group` = '".$group['id']."' AND `time` = '0'") > 0)
            {
                DB :: $pdo -> query("UPDATE `groups_files` SET `time` = '".time()."', `id_post` = '".$last_id."' WHERE `id_user` = '".$user['id']."' AND `id_group` = '".$group['id']."' AND `time` = '0'");
            }
         
          
            system :: redirect("Сообщение успешно добавлено.", "/groups/?group=".$group['id']."");
    	} else {
    		$errMsg = "Неизвестная ошибка.!";
    	}
    }
}

	
	system :: show($errMsg);







