<?

include_once '../../sys/inc/start.php';
include_once '../../sys/inc/compress.php';
include_once '../../sys/inc/sess.php';
include_once '../../sys/inc/home.php';
include_once '../../sys/inc/settings.php';
include_once '../../sys/inc/db_connect.php';
include_once '../../sys/inc/ipua.php';
include_once '../../sys/inc/fnc.php';
include_once '../../sys/inc/adm_check.php';
include_once '../../sys/inc/user.php';

$my = null;
$frend = null;
$all = null;

only_reg();


$set['title']='Лента сообществ';
include_once '../../sys/inc/thead.php';

/*
===============================
Очищение списка непрочитанных
===============================
*/
if (isset($_GET['read']) && $_GET['read']=='all')
{
	if (isset($user))
	{
		mysql_query("UPDATE `comm_lenta` SET `read` = '1' WHERE `id_user` = '$user[id]'");
		$_SESSION['message'] = 'Список непрочитанных очищен';
		header("Location: ?page=".intval($_GET['page'])."");
		exit;
	}
}


/*
===============================
Полная очистка ленты
===============================
*/
if (isset($_GET['delete']) && $_GET['delete']=='all')
{
	if (isset($user))
	{
		mysql_query("DELETE FROM `comm_lenta` WHERE `id_user` = '$user[id]'");
		$_SESSION['message'] = 'Лента успешно очищена';
		header("Location: ?");
		exit;
	}
}
title();
err();
aut();
$comm = mysql_result(mysql_query("SELECT COUNT(`read`) FROM `comm_lenta` WHERE `id_user` = '$user[id]' AND `read` = '0'"), 0); // сообщества

if ($comm > 0)$comm = '<font color=red>('.$comm.')</font>';
else $comm = null;

$lenta = mysql_result(mysql_query("SELECT COUNT(`read`) FROM `tape` WHERE `id_user` = '$user[id]' AND `read` = '0' "),0); // Лента

if ($lenta > 0)$lenta = '<font color=red>('.$lenta.')</font>';
else $lenta = null;




echo "<div class='foot'>";

echo "<a href='/user/tape/comm.php' class='activ'><b>Сообщества</b> $comm</a> / ";

echo "<a href='/user/tape/'>Лента $lenta</a> ";

echo "</div>"; 

$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `comm_lenta`  WHERE `id_user` = '$user[id]' "),0);
$k_page = k_page($k_post,$set['p_str']);
$page = page($k_page);
$start = $set['p_str'] * $page-$set['p_str'];

echo '<div class="foot">';
echo '<a href="?page=' . $page . '&amp;read=all"><img src="/style/icons/ok.gif"> Отметить всё как прочитанное</a>';
echo '</div>';

//==================================//
$q = mysql_query("SELECT * FROM `comm_lenta` WHERE `id_user` = '$user[id]' ORDER BY `time` DESC LIMIT $start, $set[p_str]");

if ($k_post == 0)
{
	echo "  <div class='mess'>\n";
	echo "Нет новых событий\n";
	echo "  </div>\n";
}

while ($post = mysql_fetch_assoc($q))
{
	$type = $post['type'];
	$avtor = get_comm($post['id_comm']);
	$name = null;
	
	if ($post['read'] == 0)
	{
		$s1 = "<font color='red'>";
		$s2 = "</font>";
		mysql_query("UPDATE `comm_lenta` SET `read` = '1' WHERE `id` = '$post[id]'");
	}
	else
	{
		$s1 = null;
		$s2 = null;
	}
	echo"<div class='nav2'>";
	$ccomm = mysql_fetch_array(mysql_query("SELECT * FROM `comm` WHERE `id` = '$post[id_comm]'"));
	if($ccomm!=NULL){
	/*
	===============================
	Файлы начало
	===============================
	*/	
	if($type == 'obmen'){
		$files = mysql_fetch_array(mysql_query("SELECT * FROM `comm_obmen` WHERE `id` = '$post[id_object]' AND `id_comm` = '$post[id_comm]' AND `type` = '1'"));
		if($files!=NULL){
		$idfile = intval($files['id_object']);
	$filess = mysql_fetch_array(mysql_query("SELECT * FROM `obmennik_files`  WHERE `id` = '$idfile'"));
		if($filess!=NULL){
		$dir = mysql_fetch_assoc(mysql_query("SELECT * FROM `comm_obmen` WHERE `id` = '$files[id_dir]' LIMIT 1"));
		echo avatar_comm($avtor['id']); echo comm_name($avtor['id']); 
		echo ' '.$s1.'новые файлы в папке'.$s2.' <img src="/style/themes/'.$set['set_them'].'/loads/14/dir.png" alt="*"> <a href="/comm/obmen/'.$avtor['id'].'/'.$dir['id'].'/">'.text($dir['name']).'</a> ';
		echo vremja($post['time']);
		echo"</div><div class='nav1'>";
		$ras=$filess['ras'];
		if (is_file(H.'style/themes/'.$set['set_them'].'/loads/14/'.$ras.'.png'))
echo "<img src='/style/themes/$set[set_them]/loads/14/$ras.png' alt='$ras' /> \n";
else 
echo "<img src='/style/themes/$set[set_them]/loads/14/file.png' alt='file' /> \n";

if ($set['echo_rassh']==1)$ras=$filess['ras'];else $ras=NULL;

		echo ''.$s1.'<a href="/comm/obmenfiles/'.$filess['id'].'/'.$dir['id'].'/?page='.$page.'"><b>'.text($filess['name']).'.'.$ras.'</b></a> ('.size_file($filess['size']).') '.$s2.'';		}else{
			echo avatar_comm($avtor['id']); echo comm_name($avtor['id']); 
			echo' ';
			echo vremja($post['time']);
			echo"</div><div class='nav1'>$s1 Файл уже удален!$s1";
		}
		}else{
			echo avatar_comm($avtor['id']); echo comm_name($avtor['id']); 
			echo' ';
			echo vremja($post['time']);
			echo"</div><div class='nav1'>$s1 Файл уже удален!$s1";
		}
		
	}
	/*
	===============================
	Файлы конец
	===============================
	*/	
	
	
	/*
	===============================
	Форум начало
	===============================
	*/	
	if($type == 'forum'){
		$forum = mysql_fetch_array(mysql_query("SELECT * FROM `comm_forum_theme`  WHERE `id` = '$post[id_object]' AND `id_comm` = '$post[id_comm]'"));
		if($forum!=NULL){
		echo avatar_comm($avtor['id']); echo comm_name($avtor['id']); 
		echo ' '.$s1.'новая тема на форуме'.$s2.' ';
		echo vremja($post['time']);
		echo"</div><div class='nav1'>";
		echo '<img src="/style/themes/' . $set['set_them'] . '/forum/14/them_' . $forum['up'] . $forum['close'] . '.png" alt="" />';

echo ''.$s1.'<a href="/comm/theme/' . $forum['id'] . '/">' . text($forum['name']) . '</a>'.$s2.' ';
		echo '<div class="text">' . output_text($forum['text']) . '</div>';
		}else{
			echo avatar_comm($avtor['id']); echo comm_name($avtor['id']); 
		echo ' ';
		echo vremja($post['time']);
		echo"</div><div class='nav1'>$s1 Тема уже удалена!$s2";
		}
	}
	/*
	===============================
	Форум конец
	===============================
	*/	
	
	
	/*
	===============================
	Новости начало
	===============================
	*/	
	if($type == 'news'){
		$news = mysql_fetch_array(mysql_query("SELECT * FROM `comm_news`  WHERE `id` = '$post[id_object]' AND `id_comm` = '$post[id_comm]'"));
		if($news!=NULL){
		echo avatar_comm($avtor['id']); echo comm_name($avtor['id']); 
		echo ' '.$s1.'новая новость'.$s2.' ';
		echo vremja($post['time']);
		echo"</div><div class='nav1'>";
		echo '<a id="link_menu" href="/comm/readnews/' . $news['id'] . '/"><img src="/style/icons/rss.png" alt="*" /> ' . text($news['title']) . '</a> ';
		echo '<div class="text">' . output_text($news['msg']) . '</div>';
		}else{
			echo avatar_comm($avtor['id']); echo comm_name($avtor['id']); 
		echo ' ';
		echo vremja($post['time']);
		echo"</div><div class='nav1'>$s1 Новость уже удалена!$s1";
		}
	}


	}else{
		echo"$s1 Сообщество уже удалено!$s1";
	}

	/*
	===============================
	Новости конец
	===============================
	*/	
echo '</div>';
}

if ($k_page>1)str('?',$k_page,$page); 

//=================================//

echo '<div class="foot">';
echo '<a href="?page=' . $page . '&amp;delete=all"><img src="/style/icons/delete.gif"> Очистить ленту</a>';
echo '</div>'; 
include_once '../../sys/inc/tfoot.php';
?>