<?php

function group_name($id,$users_hide=0) {
$arr = mysql_fetch_array(mysql_query("SELECT * FROM `groups` WHERE `id` = '".$id."' LIMIT 1"));
if (!empty($arr['avatar'])) $group_ava = '<img class="avatar_icons" src="'.URL.'/files/groups/avatars/'.$id.'/icons/'.$arr['avatar'].'"/>';
else $group_ava = '<img class="avatar_icons" src="'.URL.'/design/img/noavatar.png"/>';
$group_name = '<a href="'.URL.'/groups/?id='.$arr['id'].'" onclick="Page.Go(this.href); return false">'.$group_ava.'<b>'.$arr['name'].'</b></a>'.($users_hide==0?'<ul>'.lang('Участники','Учасники').': '.$arr['count_users'].'</ul>':'');
return $group_name;
}

function group_name2($id) {
$arr = mysql_fetch_array(mysql_query("SELECT `name` FROM `groups` WHERE `id` = '".$id."' LIMIT 1"));
return '<a href="'.URL.'/groups/?id='.$id.'" onclick="Page.Go(this.href); return false">'.$arr['name'].'</a>';
}

function group_like($modul, $id, $arr_ulike, $arr_clike)
{
	global $user_id;
	if (!empty($user_id))
	{
		if (!in_array($user_id, explode("||", substr($arr_ulike, 1, -1)))) $img_like = '<img src="'.URL.'/design/img/like.png"/>'; else $img_like = '<img src="'.URL.'/design/img/like_ok.png"/>';
		echo '<span id="like_'.$id.'"><a class="crl" class="'.$id.'" href="'.URL.'/groups/'.$modul.'/like.php?id='.$id.'" onclick="Like.Go(this.href,'.$id.'); return false">'.$img_like.''.($arr_clike>0?'<b>'.$arr_clike.'</b>':'').'</a></span>';
	}
	else echo '<a class="crl" href="'.URL.'/groups/avatars/preview.php?fid='.$id.'" onclick="Page.Go(this.href); return false"><img src="'.URL.'/design/img/like.png"/>'.($arr_clike>0?'<b>'.$arr_clike.'</b>':'').'</a>';
}

function group_wall_post($arr, $hide_post_panel=0, $search=false, $from_group=false)
{
	global $user_id;
	
if ($arr == false) return '<ul>'.err(lang('Запись не найдена','Запис не знайдений')).'</ul>';

	if ($hide_post_panel == 0) echo '<div class="block">';
	echo ($arr['from_group']>0?group_name($arr['wall_id'],1):user_name($arr['user_id'])).'<ul><a href="'.URL.'/groups/wall/post.php?id='.$arr['id'].'" onclick="Page.Go(this.href); return false">'.($arr['type']=='repost'?'<img src="'.URL.'/design/img/repost.png"/>':'').' '.vtime($arr['time']).'</a></ul>';
	echo '<ul>'.($search==true?str_replace($search,'<span style="background:#EEEEEE;">'.$search.'</span>',links(smiles(hastag(cut($arr['text'],URL.'/groups/wall/post.php?id='.$arr['id'].'&text=full'))))):links(smiles(hastag(cut($arr['text'],URL.'/groups/wall/post.php?id='.$arr['id'].'&text=full'))))).'</ul>';
	if ($from_group==true) if ($arr['from_group']==0) echo '<ul>'.group_name2($arr['wall_id']).'</ul>';


	if ($arr['type'] == 'post')
	{		
	
	
	
		if (!empty($arr['photos']))
		{
			echo '<ul><p>';
			$q = explode("||", substr($arr['photos'], 1, -1));
			$count = count($q);
			for ($i = 0; $i < $count; $i++)
			{
				if (file_exists(HOME .'/files/'.($arr['from_group']>0?'groups/wall/'.$arr['wall_id']:'wall/'.$arr['user_id']).'/photos/'.$q[$i])) echo '<a href="'.URL.'/groups/wall/post.php?id='.$arr['id'].'&n='.($i+1).'" onclick="Page.Go(this.href); return false"><img class="'.($count>1?'preview_mini':'preview').'" src="'.URL.'/files/'.($arr['from_group']>0?'groups/wall/'.$arr['wall_id']:'wall/'.$arr['user_id']).'/photos/'.($count>1?'mini':'preview').'/'.$q[$i].'"/></a>';
				else echo '<img class="preview_mini" src="'.URL.'/design/img/image_not_found.png"/>';
			}
			echo '</p></ul>';
		}
		if (!empty($arr['audio']))
		{
			echo '<ul><p>';
			$q = explode("||", substr($arr['audio'], 1, -1));
			$count = count($q);
			for ($i = 0; $i < $count; $i++)
			{
				echo '<p>'.track($q[$i]).'</p>';
			}
			echo '</p></ul>';
		}
		if ($hide_post_panel == 0)
		{
			echo '<div class="post_panel">
			<a style="float:left;" id="block_menu_'.$arr['id'].'" href="" onclick="BlockMenu.Open('.$arr['id'].'); return false"><img id="block_menu_'.$arr['id'].'" src="'.URL.'/design/img/menu_show.png"/></a>
			<a class="crl" href="'.URL.'/groups/wall/post.php?id='.$arr['id'].'" onclick="Page.Go(this.href); return false"><img src="'.URL.'/design/img/comm.png"/>'.($arr['comm']>0?'<b>'.$arr['comm'].'</b>':'').'</a>';
			echo group_repost('wall',$arr['id'],$arr['urepost'],$arr['crepost'],$arr['user_id']);
			echo group_like('wall',$arr['id'],$arr['ulike'],$arr['clike'],$arr['user_id']);
			echo '</div>';
		}
	
		
		
	}
	else if ($arr['type'] == 'update_avatar')
	{
	
	
	
		$arr_ava = mysql_fetch_array(mysql_query("SELECT * FROM `groups_avatars` WHERE `name` = '".$arr['photos']."' AND `group_id` = '".$arr['wall_id']."' LIMIT 1"));
		echo '<ul style="color:#777777;">'.lang('сообщество обновило','спільнота оновила').' аватарку</ul>';
		if (file_exists(HOME .'/files/groups/avatars/'.$arr['wall_id'].'/preview/'.$arr['photos'])) echo '<ul><p><a href="'.URL.'/groups/avatars/preview.php?fname='.$arr['photos'].'" onclick="Page.Go(this.href); return false"><img class="preview" src="'.URL.'/files/groups/avatars/'.$arr['wall_id'].'/preview/'.$arr['photos'].'"/></a></p></ul>';
		else echo '<ul><img class="preview_mini" src="'.URL.'/design/img/image_not_found.png"/></ul>';
		if ($hide_post_panel == 0)
		{
			echo '<div class="post_panel">
			<a style="float:left;" id="block_menu_'.$arr['id'].'" href="" onclick="BlockMenu.Open('.$arr['id'].'); return false"><img id="block_menu_'.$arr['id'].'" src="'.URL.'/design/img/menu_show.png"/></a>';
			echo group_repost('wall',$arr['id'],$arr['urepost'],$arr['crepost'],$arr['user_id']);
			echo group_like('avatars',$arr_ava['id'],$arr_ava['ulike'],$arr_ava['clike'],$arr['user_id']);
			echo '</div>';
		}
	}
	if ($hide_post_panel == 0) echo '</div>';
}


function group_repost($modul, $id, $arr_urepost, $arr_crepost)
{
	global $user_id;
	if (!empty($user_id))
	{
		if (!in_array($user_id, explode("||", substr($arr_urepost, 1, -1)))) $img_repost = '<img src="'.URL.'/design/img/repost.png"/>'; else $img_repost = '<img src="'.URL.'/design/img/repost_ok.png"/>';
		echo '<span id="'.$id.'"><a class="crl" href="'.URL.'/groups/'.$modul.'/repost.php?id='.$id.'" onclick="Page.Go(this.href); return false">'.$img_repost.'<b>'.($arr_crepost>0?'<b>'.$arr_crepost.'</b>':'').'</b></a></span>';
	}
	else echo '<a class="crl" href="'.URL.'/groups/wall/post.php?id='.$id.'" onclick="Page.Go(this.href); return false"><img src="'.URL.'/design/img/repost.png"/><b>'.($arr_crepost>0?'<b>'.$arr_crepost.'</b>':'').'</b></a>';
}

?>