<?php

require_once '../incfiles/core.php';
require_once '../incfiles/func.php';
require_once '../incfiles/auth.php';
require_once '../incfiles/user.php';

if (empty($user_id)) go(URL);

if (!empty($_GET['from']) && is_numeric($_GET['from']) && !empty($_GET['fid']) && is_numeric($_GET['fid']) && !empty($_GET['target']))
{
	$from = abs(intval($_GET['from']));
	$fid = abs(intval($_GET['fid']));

	$arr_pl = mysql_fetch_array(mysql_query("SELECT * FROM `audioplaylist` WHERE `user_id` = '".$user_id."' LIMIT 1"));
	$arr_pl_lists = implode(",", array(substr(str_replace("||",",",$arr_pl['tracks']),1,-1)));

	if ($_GET['target'] == 'group_wall') $result1 = mysql_query("SELECT * FROM `groups` WHERE `id` = '".$from."' LIMIT 1");
	else $result1 = mysql_query("SELECT * FROM `users` WHERE `id` = '".$from."' LIMIT 1");
	$result2 = mysql_query("SELECT * FROM `audio` WHERE `id` IN (".$arr_pl_lists.") LIMIT 1");
	if (mysql_num_rows($result1) == true && mysql_num_rows($result2) == true)
	{
		$arr_audio = mysql_fetch_array(mysql_query("SELECT * FROM `audio` WHERE `id` ='".$fid."' LIMIT 1"));
	}
	else go(URL);
}
else go(URL);



if (mysql_result(mysql_query("SELECT COUNT(`id`) FROM `wall_cache` WHERE `user_id` = '".$user_id."' LIMIT 1"),0) == false) mysql_query("INSERT INTO `wall_cache` SET `user_id` = '".$user_id."'");
$arr_wall_cache = mysql_fetch_array(mysql_query("SELECT * FROM `wall_cache` WHERE `user_id` = '".$user_id."' LIMIT 1"));



if ($_GET['target'] == 'wall' || $_GET['target'] == 'group_wall')
{
	if ($arr_wall_cache['count_audio'] < 1000) mysql_query("UPDATE `wall_cache` SET `audio` = '".$arr_wall_cache['audio']."|".$arr_audio['id']."|', count_audio=count_audio+1 WHERE `user_id` = '".$user_id."' LIMIT 1");
	
	go(URL.'/'.($_GET['target']=='group_wall'?'groups/':'').'?id='.$from);
}

?>