<?php 
	$id = (int)abs($_GET['new']);
	$code = (int)abs($_GET['c']);

	$ank = profile :: getUser($id);

	$code = (int)abs($_GET['c']);
	$queyFriedQuery = DB :: $pdo -> querySingle("SELECT COUNT(*) FROM `query_friends` WHERE `id_user` = '".$user['id']."' AND `id_friend` = '".$id."' AND `code` = '".$code."'"); 

	if ($queyFriedQuery > 0) {
		DB :: $pdo -> query("INSERT INTO `friends` SET `id_user` = '".$user['id']."', `id_friend` = '".$ank['id']."'");
		DB :: $pdo -> query("INSERT INTO `friends` SET `id_user` = '".$ank['id']."', `id_friend` = '".$user['id']."'");
		
		DB :: $pdo -> query("UPDATE `users` SET `count_friends`=`count_friends`+1 WHERE `id` = ?;", array($user['id']));
		DB :: $pdo -> query("UPDATE `users` SET `count_friends`=`count_friends`+1 WHERE `id` = ?;", array($ank['id']));
		
		DB :: $pdo -> query("UPDATE `users` SET `count_fr_new`=`count_fr_new`-1 WHERE `id` = ?;", array($user['id']));
		
		DB :: $pdo -> query("DELETE FROM `query_friends` WHERE `id_user` = '".$user['id']."' AND `id_friend` = '".$ank['id']."'");
        notif::init()->add_friend([
            'id_author' => $ank['id'],
            'id_user' => $user['id'],
            'id_post' => $code
        ]);
      //  DB:: $pdo->query("UPDATE `users` SET `count_new_notice` = `count_new_notice`+1 WHERE `id` = '".$ank['id']."' LIMIT 1;");

		system :: redirect("Предложение дружбы принято!", $link."?id={$user['id']}");
	} else { system :: redirect("Предложение дружбы не найдено.", $link."?id={$user['id']}", 1); }