<?php

if (!empty($_POST['form_repost']))
{
	$text = check($_POST['text']);
	$text = substr($text, 0, 10000);

	if (mysql_query("INSERT INTO `wall` SET
	`user_id` = '".$user_id."',
	`wall_id` = '".$user_id."',
	`repost_id` = '".$arr_post['id']."',
	`text` = '".$text."',
	`type` = 'repost',
	`time` = '".time()."'
	") == true)
	{
	
		if (!in_array($user_id, explode("||", substr($arr_post['urepost'], 1, -1)))) mysql_query("UPDATE `wall` SET `urepost` = '|".$user_id."|".$arr_post['urepost']."', `crepost` = '".($arr_post['crepost']+1)."' WHERE `id` = '".$arr_post['id']."' LIMIT 1");
		if (!in_array($user_id, explode("||", substr($arr_post['ulike'], 1, -1)))) mysql_query("UPDATE `wall` SET `ulike` = '|".$user_id."|".$arr_post['ulike']."', `clike` = '".($arr_post['clike']+1)."' WHERE `id` = '".$arr_post['id']."' LIMIT 1");
		
		if ($arr_post['type'] == 'update_avatar')
		{
			$arr_ava = mysql_fetch_array(mysql_query("SELECT * FROM `avatars` WHERE `name` = '".$arr_post['photos']."' AND `user_id` != '".$user_id."' LIMIT 1"));
			if (!in_array($user_id, explode("||", substr($arr_ava['ulike'], 1, -1)))) mysql_query("UPDATE `avatars` SET `ulike` = '|".$user_id."|".$arr_ava['ulike']."', `clike` = '".($arr_ava['clike']+1)."' WHERE `id` = '".$arr_ava['id']."' LIMIT 1");
		}
		
		if (!empty($rid))
		{
			if (!in_array($user_id, explode("||", substr($arr_repost['urepost'], 1, -1)))) mysql_query("UPDATE `wall` SET `urepost` = '|".$user_id."|".$arr_repost['urepost']."', `crepost` = '".($arr_repost['crepost']+1)."' WHERE `id` = '".$rid."' LIMIT 1");
			if (!in_array($user_id, explode("||", substr($arr_repost['ulike'], 1, -1)))) mysql_query("UPDATE `wall` SET `ulike` = '|".$user_id."|".$arr_repost['ulike']."', `clike` = '".($arr_repost['clike']+1)."' WHERE `id` = '".$rid."' LIMIT 1");
			
			$id = $arr_repost['id'];
			$arr_post['user_id'] = $arr_repost['user_id'];
			$arr_post['urepost'] = $arr_repost['urepost'];
		}
		
		if (!in_array($user_id, explode("||", substr($arr_post['urepost'], 1, -1))) && mysql_query("INSERT INTO `notifications` SET
		`from_id` = '".$user_id."',
		`sex` = '".$user['sex']."',
		`for_id` = '".$arr_post['user_id']."',
		`mod` = 'wall',
		`type` = 'repost',
		`refid` = '".$id."',
		`time` = '".time()."',
		`count` = 1,
		`new` = 1
		") == true) mysql_query("UPDATE `users` SET `notifications` = 1, notifications_journal=notifications_journal+1 WHERE `id` = '".$arr_post['user_id']."'");
		
		mysql_query("UPDATE `users` SET `count_wall` = '".($user['count_wall']+1)."' WHERE `id` = '".$user_id."'");
	}
	go(URL.'/?id='.$user_id);
}

?>