<?

/*

Сделано © alex-borisi

Все права защищены

http://nasimbe.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/user.php';

only_reg(); 







switch (@$_GET['type']) {

case 'favorite':

$type='favorite';

$type_name='Избранные';

break;

case 'ignor':

$type='ignor';

$type_name='Игнорируемые';

break;

case 'deleted':

$type='deleted';

$type_name='Удаленные';

break;

default:

$type='common';

$type_name='Общие';

break;

}





$set['title']=$type_name.' контакты';

include_once 'sys/inc/thead.php';

title();









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

{

$ank=get_user($_GET['id']);

if ($ank)

{

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

{

switch ($_GET['act']) {

case 'add':

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `users_konts` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]'"), 0)==1)

$err[]='Этот пользователь уже есть в вашем списке контактов';

else

{

mysql_query("INSERT INTO `users_konts` (`id_user`, `id_kont`, `time`) VALUES ('$user[id]', '$ank[id]', '$time')");

msg ('Контакт успешно добавлен');

}



break;

case 'del':

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `users_konts` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]'"), 0)==0)

$warn[]='Этого пользователя нет в вашем списке контактов';

else

{

mysql_query("UPDATE `users_konts` SET `type` = 'deleted', `time` = '$time' WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]' LIMIT 1");

msg ('Контакт перенесен в группу удаленные');

$type='deleted';

}

break;

}

}

}

else

$err[]='Пользователь не найден';

}



if (isset($_GET['act']) && $_GET['act']==='edit_ok' && isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `user` WHERE `id` = '".intval($_GET['id'])."' LIMIT 1"),0)==1)

{

$ank=get_user(intval($_GET['id']));

if (mysql_result(mysql_query("SELECT COUNT(*) FROM `users_konts` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]'"), 0)==1)

{

$kont=mysql_fetch_array(mysql_query("SELECT * FROM `users_konts` WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]'"));

if (isset($_POST['type']) && preg_match('#^(common|ignor|favorite|deleted)$#',$_POST['type']) && $_POST['type']!=$type)

{

mysql_query("UPDATE `users_konts` SET `type` = '$_POST[type]', `time` = '$time' WHERE `id_user` = '$user[id]' AND `id_kont` = '$ank[id]' LIMIT 1");

msg ('Контакт успешно перенесен');

}

}

else

$err[]='Контакт не найден';

}



aut();

err();





if ($type=='deleted')echo "<div class='mess'>Контакты из корзины удаляются через 30 дней</div>\n";

if ($type=='ignor')echo "<div class='mess'>Уведомления о сообщениях от этих контактов не появляются</div>\n";

if ($type=='favorite')echo "<div class='mess'>Уведомления о сообщениях от этих контактов выделяются</div>\n";





$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `users_konts` WHERE `id_user` = '$user[id]' AND `type` = '$type'"), 0);

if ($k_post==0 && $type=='common')echo "<div class='mess'>У вас еще нет добавленных контактов</div>\n";



if ($k_post){

$k_page=k_page($k_post,$set['p_str']);

$page=page($k_page);

$start=$set['p_str']*$page-$set['p_str'];

echo "<table class='post'>\n";

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

while ($post = mysql_fetch_array($q))

{

$ank_kont=get_user($post['id_kont']);

$k_mess=mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `id_user` = '$ank_kont[id]' AND `id_kont` = '$user[id]'"), 0);

$k_new_mess=mysql_result(mysql_query("SELECT COUNT(*) FROM `mail` WHERE `id_user` = '$ank_kont[id]' AND `id_kont` = '$user[id]' AND `read` = '0'"), 0);









echo "<table class='post'>\n";

echo "   <tr>\n";

if ($set['set_show_icon']==2){

echo "  <td class='icon48'>\n";

avatar($ank_kont['id']);

echo "  </td>\n";

}

elseif ($set['set_show_icon']==1)

{

echo "  <td class='icon14'>\n";

echo "".status($ank_kont['id'])."";

echo "  </td>\n";

}

echo "  <td class='p_t'>\n";

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

echo "  </td>\n";

echo "   </tr>\n";

echo "</table>\n";



echo "<table class='post'>\n";

echo "   <tr>\n";

if ($set['set_show_icon']==1)echo "  <td class='p_m' colspan='2'>\n"; else echo "  <td class='p_m'>\n";

echo ($k_new_mess!=0?'<img src="/style/icons/new_mess.gif" alt="*" /> ':'<img src="/style/icons/msg.gif" alt="*" /> ')."<a href=\"/mail.php?id=$ank_kont[id]\">".($post['name']!=null?$post['name']:'Сообщения')."</a> \n";

echo ($k_new_mess!=0?'<font color="red">':null)."".($k_new_mess!=0?'+'.$k_new_mess:$k_mess)."".($k_new_mess!=0?'</font> ':null);



if (isset($_GET['act']) && $_GET['act']==='edit' && isset($_GET['id']) && $_GET['id']==$ank_kont['id'])

{

echo "<form method='post' action='?type=$type&amp;act=edit_ok&amp;id=$ank_kont[id]&amp;page=$page'>\n";

echo "Группа:<br />\n";

echo "<select name='type'>\n";

echo "<option value='common'".($type=='common'?" selected='selected'":null).">Общая</option>\n";

echo "<option value='favorite'".($type=='favorite'?" selected='selected'":null).">Избранные</option>\n";

echo "<option value='ignor'".($type=='ignor'?" selected='selected'":null).">Игнор</option>\n";

echo "<option value='deleted'".($type=='deleted'?" selected='selected'":null).">Удаленные</option>\n";

echo "</select><br />\n";

echo "<input type='submit' name='apply' value='Применить' /><br />\n";

echo "</form>\n";

echo "<a href='?type=$type&amp;id=$ank_kont[id]&amp;page=$page'>Отмена</a><br />\n";

}

else

{

echo " [<a href='?type=$type&amp;act=edit&amp;id=$ank_kont[id]&amp;page=$page'><img src='/style/icons/edit.gif' alt='*' /> ред</a>] \n";

}



if ($type!='deleted')echo " [<a href='/konts.php?type=$type&amp;act=del&amp;id=$ank_kont[id]'><img src='/style/icons/delete.gif' alt='*' /> удл</a>]\n";













echo "  </td>\n";

echo "   </tr>\n";

echo "</table>\n";

}







if ($k_page>1)str("?type=$type&amp;",$k_page,$page); // Вывод страниц

}

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

echo ($type=='common'?'<b>':null)."<img style='padding:2px;' src='/style/icons/activ.gif' alt='*' /> <a href='?type=common'>Активные</a>".($type=='common'?'</b>':null)." (".mysql_result(mysql_query("SELECT COUNT(*) FROM `users_konts` WHERE `id_user` = '$user[id]' AND `type` = 'common'"), 0).")<br />\n";

echo ($type=='favorite'?'<b>':null)."<img style='padding:2px;' src='/style/icons/star_fav.gif' alt='*' /> <a href='?type=favorite'>Избранные</a>".($type=='favorite'?'</b>':null)." (".mysql_result(mysql_query("SELECT COUNT(*) FROM `users_konts` WHERE `id_user` = '$user[id]' AND `type` = 'favorite'"), 0).")<br />\n";

echo ($type=='ignor'?'<b>':null)."<img style='padding:2px;' src='/style/icons/spam.gif' alt='*' /> <a href='?type=ignor'>Игнорируемые</a>".($type=='ignor'?'</b>':null)." (".mysql_result(mysql_query("SELECT COUNT(*) FROM `users_konts` WHERE `id_user` = '$user[id]' AND `type` = 'ignor'"), 0).")<br />\n";

echo ($type=='deleted'?'<b>':null)."<img style='padding:2px;' src='/style/icons/trash.gif' alt='*' /> <a href='?type=deleted'>Корзина</a>".($type=='deleted'?'</b>':null)." (".mysql_result(mysql_query("SELECT COUNT(*) FROM `users_konts` WHERE `id_user` = '$user[id]' AND `type` = 'deleted'"), 0).")<br />\n";

echo "</div>\n";

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

if(isset($_SESSION['refer']) && $_SESSION['refer']!=NULL && otkuda($_SESSION['refer']))

echo "&laquo;<a href='$_SESSION[refer]'>".otkuda($_SESSION['refer'])."</a><br />\n";

echo "&laquo;<a href='umenu.php'>Мое меню</a><br />\n";

echo "</div>\n";

include_once 'sys/inc/tfoot.php';

?>