<?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['id']) && is_numeric($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(`id`) FROM `groups_avatars` WHERE `id` = '".abs(intval($_GET['id']))."'"),0) == true)
{
	$id = abs(intval($_GET['id']));
	$arr = mysql_fetch_array(mysql_query("SELECT `id`, `group_id`, `ulike`, `clike` FROM `groups_avatars` WHERE `id` = '".$id."' LIMIT 1"));

	if (!in_array($user_id, explode("||", substr($arr['ulike'], 1, -1))))
	{
		if (!empty($arr['ulike'])) $new_like = '|'.$user_id.'|'.$arr['ulike']; else $new_like = '|'.$user_id.'|';
		
		if (mysql_query("UPDATE `groups_avatars` SET
		`ulike` = '".$new_like."',
		`clike` = '".($arr['clike']+1)."'
		WHERE `id` = '".$id."' LIMIT 1") == true)
		{
			echo '<a class="crl" href="'.URL.'/groups/avatars/like.php?id='.$id.'" onclick="Like.Go(this.href,'.$id.'); return false"><img src="'.URL.'/design/img/like_ok.png"/><b>'.($arr['clike']+1).'</b></a>';
		}
	}
	else
	{
		$del_ulike = str_replace("|".$user_id."|", "", $arr['ulike']);
		
		if (mysql_query("UPDATE `groups_avatars` SET
		`ulike` = '".$del_ulike."',
		`clike` = '".($arr['clike']-1)."'
		WHERE `id` = '".$id."' LIMIT 1") == true)
		{
			echo '<a class="crl" href="'.URL.'/groups/avatars/like.php?id='.$id.'" onclick="Like.Go(this.href,'.$id.'); return false"><img src="'.URL.'/design/img/like.png"/><b>'.(($arr['clike']-1)==0?'':($arr['clike']-1)).'</b></a>';
		}
	}
}

if(empty($_SERVER['HTTP_X_REQUESTED_WITH']) or strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {go(URL.'/groups/avatars/?fid='.$id.'');}

 
?>