<?php

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

if (!empty($_GET['id']) && is_numeric($_GET['id']))
{
	$id = abs(intval($_GET['id']));
	$result = mysql_query("SELECT * FROM `groups` WHERE `id` = '".$id."' LIMIT 1");
	if (mysql_num_rows($result) == true) $arr_group = mysql_fetch_array($result);
	else go(URL);
}
else go(URL);

	if (in_array($user_id, explode("||", substr($arr_group['blacklist'], 1, -1)))) go(URL.'/groups/?id='.$id);

$title = checkout($arr_group['name']).' :: Аватарки';
require_once '../../incfiles/head.php';
echo group_access($arr_group);

if (in_array($user_id, explode("||", substr($arr_group['admins'], 1, -1))))
{
	require_once 'handler/upload.php';
	require_once 'handler/del_avatar.php';
}

	echo '<div class="title">
	<a href="'.URL.'/groups/?id='.$id.'" onclick="Page.Go(this.href); return false">'.lang('Сообщество','Спільнота').'</a>
	<a class="title_a_hover" href="'.URL.'/groups/avatars/?id='.$id.'" onclick="Title.Open(); return false">Аватарки <img src="'.URL.'/design/img/title_menu.png"/></a>
	</div>';
	if (!empty($user_id) && $user_id == $arr_group['user_id'])
	{
		echo '<div id="title_menu">
		<div class="block">
		<div class="for_pc">
		<button class="button" id="upload">'.lang('Загрузить','Завантажити').' аватарку</button>
		</div>
		<div class="for_mobile">
		'.lang('Загрузить','Завантажити').' аватарку:<br/>
		<form action="'.URL.'/groups/avatars/?id='.$id.'" method="post" enctype="multipart/form-data">
		<input class="input2" name="file" type="file"/> 
		<input class="button2" type="submit" name="upl" value="'.lang('Загрузить','Завантажити').'" />
		</form>
		</div>
		</div></div>';
	}	
	echo '<div class="block"><center><span id="upload_avatar"></span>';

	$all = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `groups_avatars` WHERE `group_id` = '".$id."' LIMIT 1"),0);
	if ($all == true)
	{
		$cp = ceil($all/12);
		$p = (isset($_GET['p']) and is_numeric($_GET['p']) and $_GET['p']>1 and $_GET['p']<=$cp) ? $_GET['p'] : 1;
		$start = $p*12-12;
		$n = $start;
		$res = mysql_query("SELECT * FROM `groups_avatars` WHERE `group_id` = '".$id."' ORDER by `time` DESC LIMIT $start,12");
		while ($arr = mysql_fetch_array($res))
		{
			$n++;
			echo '<a href="'.URL.'/groups/avatars/preview.php?id='.$id.'&n='.$n.'" onclick="Page.Go(this.href); return false;"><img class="preview_mini" src="'.URL.'/files/groups/avatars/'.$id.'/mini/'.$arr['name'].'"></a>';
		}
	}
echo'</center></div>';

	navi($p,$cp,'/groups/avatars/?id='.$id.'&');

require_once '../../incfiles/foot.php';

?>