<?

/*

=======================================

Лента друзей для Dcms-Social

Автор: Искатель

---------------------------------------

Этот скрипт распостроняется по лицензии

движка Dcms-Social. 

При использовании указывать ссылку на

оф. сайт http://dcms-social.ru

---------------------------------------

Контакты

ICQ: 587863132

http://dcms-social.ru

=======================================

*/

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();

	

/* Класс к статусу */



if (isset($_GET['likestatus']))

{



 // Статус пользователя

$status=mysql_fetch_assoc(mysql_query("SELECT * FROM `status` WHERE `id` = '".intval($_GET['likestatus'])."' LIMIT 1"));

$ank = get_user($status['id_user']);

if ($user['id']!=$ank['id'] && mysql_result(mysql_query("SELECT COUNT(*) FROM `status_like` WHERE `id_status` = '$status[id]' AND `id_user` = '$user[id]' LIMIT 1"),0)==0){

mysql_query("INSERT INTO `status_like` (`id_user`, `time`, `id_status`) values('$user[id]', '$time', '$status[id]')");







/*

===================================

Лента

===================================

*/

$q = mysql_query("SELECT * FROM `frends` WHERE `user` = '" . $user['id'] . "' AND `i` = '1'");

while ($f = mysql_fetch_array($q))

{

$a = get_user($f['frend']);



$lentaSet = mysql_fetch_array(mysql_query("SELECT * FROM `tape_set` WHERE `id_user` = '".$a['id']."' LIMIT 1")); // Общая настройка ленты

if ($a['id'] != $ank['id'] && $f['lenta_status_like']==1 && $lentaSet['lenta_status_like']==1)

mysql_query("INSERT INTO `tape` (`id_user`,`ot_kogo`,  `avtor`, `type`, `time`, `id_file`) values('$a[id]', '$user[id]', '$status[id_user]', 'status_like', '$time', '$status[id]')"); 



}





header("Location: ?page=".intval($_GET['page'])."");

exit;

}

}





$set['title']='Лента';

include_once '../../sys/inc/thead.php';



/*

===============================

Очищение списка непрочитанных

===============================

*/

if (isset($_GET['read']) && $_GET['read']=='all')

{

if (isset($user))

{

	mysql_query("UPDATE `tape` 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 `tape` WHERE `id_user` = '$user[id]'");

	$_SESSION['message'] = 'Лента успешно очищена';

	header("Location: ?");

	exit;

}

}

title();

err();

aut();



$k_notif = mysql_result(mysql_query("SELECT COUNT(`read`) FROM `notification` WHERE `id_user` = '$user[id]' AND `read` = '0'"), 0); // Уведомления



if ($k_notif > 0)$k_notif = '<font color=red>('.$k_notif.')</font>';

else $k_notif = null;



$discuss = mysql_result(mysql_query("SELECT COUNT(`count`) FROM `discussions` WHERE `id_user` = '$user[id]' AND `count` > '0' "),0); // Обсуждения



if ($discuss > 0)$discuss = '<font color=red>('.$discuss.')</font>';

else $discuss = 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 id='comments' class='menus'>";

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

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

echo "</div>"; 

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

echo "<a href='/user/discussions/' >Обсуждения  $discuss</a>";

echo "</div>"; 

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

echo "<a href='/user/notification/'>Уведомления $k_notif</a>";

echo "</div>"; 

echo "</div>";







	$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `tape`  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 `tape` 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_user($post['avtor']);

	

	if ($post['read']==0)

	{

	$s1 = "<font color='red'>";

	$s2 = "</font>";

	}else{

	$s1 = null;

	$s2 = null;

	}



/*

===============================

Помечаем сообщение прочитанным

===============================

*/	

mysql_query("UPDATE `tape` SET `read` = '1' WHERE `id` = '$post[id]'");

	

	

	

/*

===============================

Значение переменной $name для 

определенного типа сообщения

===============================

*/

if ($type=='them' && $post['avtor']!=$user['id']) // дневники

{

	$name = 'создал'.($avtor['pol']==1?"":"а").' в форуме тему ';

}

else if ($type=='frends' && $post['avtor']!=$user['id']) // дневники

{

	$name = 'добавил'.($avtor['pol']==1?"":"а").' в друзья';

}

else if ($type=='notes' && $post['avtor']!=$user['id']) // дневники

{

	$name = 'создал'.($avtor['pol']==1?"":"а").' новый дневник';

}

else if ($type=='status_like' && $post['avtor']!=$user['id']) // статус like

{

	$name = 'считает классным статус';

}

else if ($type=='status_like' && $post['avtor']==$user['id'])

{

	$name = 'считает классным ваш статус';

}

else if ($type=='status' && $post['avtor']!=$user['id'])

{

	$name = 'установил'.($avtor['pol']==1?"":"а").' новый статус';

}

else if ($type=='album' && $post['avtor']!=$user['id'])

{

	$name = 'новые фото в альбоме';

}

else if ($type=='obmen' && $post['avtor']!=$user['id'])

{

	$name = 'новые файлы в папке';

}

else if ($type=='avatar' && $post['avtor']!=$user['id']) // аватар

{

	if ($post['avatar'])

	$name = 'сменил'.($avtor['pol']==1?"":"а").' фото на главной';

	else

	$name = 'установил'.($avtor['pol']==1?"":"а").' фото на главной';	

}else{



	$name = null;

}







/*

===============================

Лайки статусов

===============================

*/

if ($type=='status_like' || $type=='status')

{

	$status=mysql_fetch_assoc(mysql_query("SELECT * FROM `status` WHERE `id` = '".$post['id_file']."' LIMIT 1"));



	$otkogo = get_user($post['ot_kogo']);

if ($status['id']){

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

	

	if ($post['ot_kogo']){

	

		echo status($otkogo['id']) . group($otkogo['id']); 

		echo " <a href='/info.php?id=$otkogo[id]'>$otkogo[nick]</a>  ".medal($otkogo['id'])." ".online($otkogo['id'])."  <a href='user.settings.php?id=$otkogo[id]'>[!]</a>";

	}else{

	

		echo status($avtor['id']) . group($avtor['id']); 

		echo " <a href='/info.php?id=$status[id_user]'>$avtor[nick]</a>  ".medal($avtor['id'])." ".online($avtor['id'])."  <a href='user.settings.php?id=$avtor[id]'>[!]</a>";

	}

	

	

	echo " $name ";

	if ($type != 'status')

	{

	

		echo status($avtor['id']) . group($avtor['id']); 

		echo "<a href='/info.php?id=$avtor[id]'>$avtor[nick]</a>  ".medal($avtor['id'])." ".online($avtor['id'])." ";

		

	}

	

	echo " $s1".vremja($post['time'])."$s2";

	echo "</div>";

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

	

	echo '<div class="st_1"></div>';

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

	echo output_text($status['msg'])."<br />";

	echo "</div>";

	

	echo "<a href='/user/status/komm.php?id=$status[id]'><img src='/style/icons/bbl4.png' alt=''/> " . mysql_result(mysql_query("SELECT COUNT(*) FROM `status_komm` WHERE `id_status` = '$status[id]'"),0) . "</a>";

	$l=mysql_result(mysql_query("SELECT COUNT(*) FROM `status_like` WHERE `id_status` = '$status[id]'"),0);

if (isset($user) && $user['id']!=$avtor['id']){

if ($user['id']!=$avtor['id'] && mysql_result(mysql_query("SELECT COUNT(*) FROM `status_like` WHERE `id_status` = '$status[id]' AND `id_user` = '$user[id]' LIMIT 1"),0)==0){

	echo " <a href='?likestatus=$status[id]&amp;page=$page'><img src='/style/icons/like.gif' alt=''/>Класс!</a> • ";

	$like = $l;

}else{

	echo " <img src='/style/icons/like.gif' alt=''/> Вы и ";

	$like = $l-1;

}

}else{

echo " <img src='/style/icons/like.gif' alt=''/> ";

	$like = $l;

}

	echo "<a href='/user/status/like.php?id=$status[id]'>$like чел.</a>";



}else{

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

	echo status($avtor['id']) . group($avtor['id'])." <a href='/info.php?id=$avtor[id]'>$avtor[nick]</a></b>";

	echo " ".medal($avtor['id'])." ".online($avtor['id'])." <a href='user.settings.php?id=$avtor[id]'>[!]</a><br />";

	echo "Статус уже удален =(";



}

}





/*

===============================

Новые друзья друзей

===============================

*/

if ($type=='frends')

{

	$frend = get_user($post['id_file']);

	

if ($frend['id']){

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

	echo status($avtor['id']) . group($avtor['id'])." <a href='/info.php?id=$avtor[id]'>$avtor[nick]</a></b> ";

	echo " ".medal($avtor['id'])." ".online($avtor['id'])." <a href='user.settings.php?id=$avtor[id]'>[!]</a> $name ";

	

	echo status($frend['id']) . group($frend['id'])." <a href='/info.php?id=$frend[id]'>$frend[nick]</a></b> ";

	echo " ".medal($frend['id'])." ".online($frend['id'])." ";

	

	echo "$s1 ".vremja($post['time'])." $s2";

	echo "</div>";



	

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

	if (mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_foto` WHERE `id_user` = '$frend[id]'"),0)>0)

	{



	echo 'Последние добавленные фото '.$frend['nick'].'<br />';

	$g = mysql_query("SELECT * FROM `gallery_foto` WHERE `id_user` = '$frend[id]' ORDER BY `id` DESC LIMIT 4");

	while ($xx = mysql_fetch_assoc($g))

	{

	$gallery=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery` WHERE `id` = '".$xx['id_gallery']."' LIMIT 1"));

	echo "<a href='/foto/$gallery[id_user]/$gallery[id]/$xx[id]/'><img style=' margin: 2px;' src='/foto/foto50/$xx[id].$xx[ras]' alt='*'/></a>";

	}

	}else{

	echo "У $frend[nick] еще нет загруженных фотографий =(";

	}

}else{

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

	echo status($avtor['id']) . group($avtor['id'])." <a href='/info.php?id=$avtor[id]'>$avtor[nick]</a></b>";

	echo " ".medal($avtor['id'])." ".online($avtor['id'])." <a href='user.settings.php?id=$avtor[id]'>[!]</a><br />";

	echo "Запись уничтожена =(";



}

}



/*

===============================

Новые фото в альбомах

===============================

*/

if ($type=='album')

{

	$gallery=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery` WHERE `id` = '".$post['id_file']."' LIMIT 1"));

	if ($post['count']>5)

	{

	$kol = '5';

	$kol2 = $post['count']-5;

	}else{

	$kol = $post['count'];

	}

	

if ($gallery['id']){

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

	echo status($avtor['id']) . group($avtor['id'])." <a href='/info.php?id=$avtor[id]'>$avtor[nick]</a></b>";

	echo" ".medal($avtor['id'])." ".online($avtor['id'])." <a href='user.settings.php?id=$avtor[id]'>[!]</a> $name <img src='/style/icons/camera.png' alt=''/>  <a href='/foto/$avtor[id]/$gallery[id]/'><b>".htmlspecialchars($gallery['name'])."</b></a> ";

	echo "$s1 ".vremja($post['time'])." $s2";

	echo "</div>";



	

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

	$as = mysql_query("SELECT * FROM `gallery_foto` WHERE `id_gallery` = '$gallery[id]' ORDER BY `id` DESC LIMIT $kol");

	while ($xx = mysql_fetch_assoc($as))

	{

	echo "<a href='/foto/$gallery[id_user]/$gallery[id]/$xx[id]/'><img style=' margin: 2px;' src='/foto/foto50/$xx[id].$xx[ras]' alt='*'/></a>";

	}

	if (isset($kol2))echo "и еще $kol2 фото";



	

}else{

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

	echo status($avtor['id']) . group($avtor['id'])." <a href='/info.php?id=$avtor[id]'>$avtor[nick]</a></b>";

	echo " ".medal($avtor['id'])." ".online($avtor['id'])." <a href='user.settings.php?id=$avtor[id]'>[!]</a><br />";

	echo "Альбом удален =(";



}

}





/*

===============================

Смена или установка аватара

===============================

*/

if ($type=='avatar')

{

$foto=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = '".$post['id_file']."' LIMIT 1"));

$avatar =mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery_foto` WHERE `id` = '".$post['avatar']."' LIMIT 1"));

$gallery=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery` WHERE `id` = '".$foto['id_gallery']."' LIMIT 1"));

$gallery2=mysql_fetch_assoc(mysql_query("SELECT * FROM `gallery` WHERE `id` = '".$avatar['id_gallery']."' LIMIT 1"));



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

	echo status($avtor['id']) . group($avtor['id'])." <a href='/info.php?id=$avtor[id]'>$avtor[nick]</a>";

	echo " ".medal($avtor['id'])." ".online($avtor['id'])." <a href='user.settings.php?id=$avtor[id]'>[!]</a> $name ";

	echo " $s1".vremja($post['time'])."$s2";

	echo "</div>";



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

	if ($foto['id'])echo "<b>".htmlspecialchars($foto['name'])."</b>";

	if ($avatar['id'])echo " &raquo; <b>".htmlspecialchars($avatar['name'])."</b>";

	if ($avatar['id'] || $foto['id'])echo "<br />";

	

	

	if ($foto['id'])echo "<a href='/foto/$avtor[id]/$gallery[id]/$foto[id]/' title='$foto[name]'>";

	echo "<img style=' max-width:50px; margin:3px;' src='/foto/foto50/$post[id_file].jpg' alt='*' />";

	if ($foto['id'])echo "</a>";

	

	if ($post['avatar'])

	{

	echo " <img src='/style/icons/arRt2.png' alt='*'/> ";

	if ($avatar['id'])echo "<a href='/foto/$avtor[id]/$gallery2[id]/$avatar[id]/' title='$avatar[name]'>";

	echo "<img style=' max-width:50px; margin:3px;' src='/foto/foto50/$post[avatar].jpg' alt='*' />";

	if ($avatar['id'])echo "</a>\n";

	}

	echo "<br />\n";

	if ($foto['id'])echo "<a href='/foto/$avtor[id]/$gallery[id]/$foto[id]/'><img src='/style/icons/bbl5.png' alt='*'/> (".mysql_result(mysql_query("SELECT COUNT(*) FROM `gallery_komm` WHERE `id_foto` = '$foto[id]'"),0).")</a> ";





}





/*

===============================

Новые темы в форуме

===============================

*/

if ($type=='them')

{

	$them=mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_t` WHERE `id` = '".$post['id_file']."' LIMIT 1"));

	$razdel=mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_r` WHERE `id` = '$them[id_razdel]' LIMIT 1"));

	$forum=mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_f` WHERE `id` = '$razdel[id_forum]' LIMIT 1"));

if ($them['id']){

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

	echo status($avtor['id']) . group($avtor['id']) . " <a href='/info.php?id=$avtor[id]'>$avtor[nick]</a> " . medal($avtor['id']) . online($avtor['id']) . " <a href='user.settings.php?id=$avtor[id]'>[!]</a> $name  $s1 ".vremja($post['time'])." $s2<br />";

	echo "</div>";



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

	echo " <a href='/forum/$forum[id]/$razdel[id]/$them[id]/'> " . $them['name'] . "</a> ";

	echo rez_text(bbcode(htmlspecialchars($them['text'])))."<br />"; 



}else{



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

	echo status($avtor['id']) . group($avtor['id']) . " <a href='/info.php?id=$avtor[id]'>$avtor[nick]</a> <a href='user.settings.php?id=$avtor[id]'>[!]</a>";

	echo medal($avtor['id']) . online($avtor['id']) . "";

	echo "</div>";

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

	echo "Тема уже удалена =( $s1 " . vremja($post['time']) . " $s2";

}

}





/*

===============================

Дневники 

===============================

*/

if ($type=='notes')

{

	$notes=mysql_fetch_assoc(mysql_query("SELECT * FROM `notes` WHERE `id` = '".$post['id_file']."' LIMIT 1"));



if ($notes['id']){



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

	echo status($avtor['id']) . group($avtor['id'])." <a href='/info.php?id=$avtor[id]'>$avtor[nick]</a> ".medal($avtor['id'])." ".online($avtor['id'])." <a href='user.settings.php?id=$avtor[id]'>[!]</a> $name 

	<b>".htmlspecialchars($notes['name'])."</b> $s1 ".vremja($post['time'])." $s2<br />";

	echo "</div>";

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



	echo rez_text(htmlspecialchars($notes['msg']))."<br />"; 

	

	echo "<a href='/plugins/notes/list.php?id=$notes[id]'><img src='/style/icons/bbl5.png' alt='*'/> 

	(".mysql_result(mysql_query("SELECT COUNT(*) FROM `notes_komm` WHERE `id_notes` = '$notes[id]'"),0).")</a>";



	

}else{



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

	echo status($avtor['id']) . group($avtor['id']) . " <a href='/info.php?id=$avtor[id]'>$avtor[nick]</a> <a href='user.settings.php?id=$avtor[id]'>[!]</a>";

	echo medal($avtor['id']) . online($avtor['id']) . "";

	echo "</div>";

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

	echo "Дневник уже удален =( $s1 " . vremja($post['time']) . " $s2";







}

}





/*

===============================

Новые файлы

===============================

*/

if ($type=='obmen')

{

	$dir=mysql_fetch_assoc(mysql_query("SELECT * FROM `user_files` WHERE `id` = '".$post['id_file']."' LIMIT 1"));

	

	if ($post['count']>5)

	{

	$kol = '5';

	$kol2 = $post['count']-5;

	}else{

	$kol = $post['count'];

	}

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

echo status($avtor['id']) . group($avtor['id'])." <a href='/info.php?id=$avtor[id]'>$avtor[nick]</a> ".medal($avtor['id'])." ".online($avtor['id'])." <a href='user.settings.php?id=$avtor[id]'>[!]</a> $name <img src='/style/themes/$set[set_them]/loads/14/dir.png' alt='*'/> <a href='/user/personalfiles/$dir[id_user]/$dir[id]/'>".htmlspecialchars($dir['name'])."</a>  $s1 ".vremja($post['time'])." $s2";



echo "</div>";

	

	

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

	$files = mysql_query("SELECT * FROM `obmennik_files` WHERE `my_dir` = '$dir[id]' ORDER BY `id` DESC LIMIT $kol");

	while ($file = mysql_fetch_assoc($files))

	{

	if ($file['id'])

	{

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

		

		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";



	echo '<a href="/user/personalfiles/'.$file['id_user'].'/'.$dir['id'].'/?id_file='.$file['id'].'&amp;page=1"><b>'.htmlspecialchars($file['name']).'.'.$ras.'</b></a> ('.size_file($file['size']).')<br />';

	}else{

	echo status($avtor['id']) . group($avtor['id'])." <a href='/info.php?id=$avtor[id]'>$avtor[nick]</a></b> <a href='user.settings.php?id=$avtor[id]'>[!]</a>";

	echo " ".medal($avtor['id'])." ".online($avtor['id'])."<br />";

	echo 'Файл уже удален =(<br />';

	}

	}

	if (isset($kol2))echo "и еще $kol2 файлов";





}

/*

===============================

The End

===============================

*/





	

	

	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>"; 

	

echo "<div class=\"foot\">\n";

echo "<img src='/style/icons/str2.gif' alt='*'> <a href='/info.php?id=$user[id]'>$user[nick]</a> | \n";

echo '<b>Лента</b>';

echo "</div>\n";





include_once '../../sys/inc/tfoot.php';

?>