<?

include 'connect.php';



//Если id получен 

if(isset($_GET['id'])){
$id=num($_GET['id']);
$req = mysql_query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1");
   if (mysql_num_rows($req)) {
   $user = mysql_fetch_assoc($req);
   } else {
   $id = $u['id'];
   }
} else {
$id = $u['id'];
}
//Если никто не выбрался
if(empty($user['id'])){
   if($u['id']){
   $req = mysql_query("SELECT * FROM `users` WHERE `id` = '".$u['id']."' LIMIT 1");
   $user = mysql_fetch_assoc($req);
   } else {
   header ("Location: index.php");
   exit;
   }
}

refresh_friends($user['id']);

$f = mysql_result(mysql_query("SELECT COUNT(*) FROM `friends` WHERE `user` = '".$user['id']."'"), 0);
$fo = mysql_result(mysql_query("SELECT COUNT(*) FROM `friends` WHERE `user` = '".$user['id']."' and `online` > '".(time()-$system['online_time'])."'"), 0);


$page_page = 1;
$title = $title.' | '.$user['login'].'';

$main_title = '<a href = "page.php?id='.$user['id'].'">'.$user['login'].'</a>';
include 'head.php';


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

if(ban($user['id'])){

$ban = mysql_fetch_assoc(mysql_query("SELECT * FROM `users_ban` WHERE `user` = '".$user['id']."' ORDER BY `time` DESC"));
$message = checkout($ban['message']);
echo '<div class = "action">
Пользователь заблокирован до '.vremya_ban($ban['time_ban']).'<br/>
Заблокировал: <a href = "page.php?id='.$ban['admin'].'">'.login($ban['admin']).'</a><br/>
'.$message.'
</div><hr>';
if($u['admin'] == 1 and $u['id'] != $user['id'] and $u[id]<=2){
echo ' <a href = "adminka.php?act=edit_users&id='.$user['id'].'"> Ред</a> | ';
if($u['admin'] == 1 and $u['id'] != $user['id']){
if(!$ban)
echo ' <a href = "adminka.php?act=ban_users&id='.$user['id'].'">Забанить</a> | ';
   else
   echo ' <a href = "adminka.php?act=delban_users&id='.$user['id'].'">Разбанить</a> | ';
echo ' <a href = "adminka.php?act=delete_users&id='.$user['id'].'">Удалить</a>';
echo '<hr>';
}
}
include 'foot.php';
exit;
}

//Админу
if($u['admin'] == 1 and $u['id'] != $user['id'] and $u[id]<=2){
echo ' <a href = "adminka.php?act=edit_users&id='.$user['id'].'"> Ред</a> | ';
if($u['admin'] == 1 and $u['id'] != $user['id']){
if(!$ban)
echo ' <a href = "adminka.php?act=ban_users&id='.$user['id'].'">Забанить</a> | ';
   else
   echo ' <a href = "adminka.php?act=delban_users&id='.$user['id'].'">Разбанить</a> | ';
echo ' <a href = "adminka.php?act=delete_users&id='.$user['id'].'">Удалить</a>';
echo '<hr>';
}
}
//Модеру
if($u['admin'] == 2 and $u['id'] != $user['id']){
if(!$ban)
echo ' <a href = "adminka.php?act=ban_users&id='.$user['id'].'"> Забанить</a> | ';
   else
   echo ' <a href = "adminka.php?act=delban_users&id='.$user['id'].'">Разбанить</a>';

}
echo '<div class="title">'. ico($user['sex'],$user['admin']) .' <b>'.$user['login'].'</b> '. online($user['online']) .'';
echo "</div>";




 echo '<td valign="top">';

			 //Статус
$req = mysql_query("SELECT * FROM `microblog_messages` WHERE `user` = '".$user['id']."' AND `main` = '1' LIMIT 1");
if (mysql_num_rows($req)) {
   $microblog = mysql_fetch_assoc($req);
   $message = checkout($microblog['message']);

   echo '
  
   <div class="status">
   '.smile($message).'
  <br><small><font color = "#209143"><b>'.vremya($microblog['time']).'</b></font><a href="microblog.php?act=view&id='.$microblog['id'].'">  Комм ('.$microblog['comm'].')</small> 
   </a></div>
   ';
  echo '<div class="status-img">';

}
    
			   
			   
		       echo '</td></div>';










  echo '<table>';
	           echo '<td valign="top">';
echo page_ava($user['id'],75);
		       echo '</td>';
		       
		      
echo '</tr></table>';




//Нравится пользователь
if($u['id'] && $u['id'] != $user['id']){
$req = mysql_query("SELECT * FROM `users_likes` WHERE `user` = '".$user['id']."' and `outuser` = '".$u['id']."' LIMIT 1");
   if (mysql_num_rows($req) == 0){
      if($_GET['likes']){
      mysql_query("INSERT INTO `users_likes` SET
      `user` = '".$user['id']."',
      `outuser` = '".$u['id']."',
      `time` = '".time()."'
      ");
	  $user['likes'] ++;
	  mysql_query("UPDATE `users` SET
      `likes` = '".$user['likes']."'
      WHERE `id` = '".$user['id']."'
      ");
	  //Записываем в журнал
      if($u['sex'] == 'm'){
      $action[0] = 'Отметил';
      $action[1] = 'ему';
      } else {
      $action[0] = 'Отметила';
      $action[1] = 'ей';
      }
      $text = $action[0].' что Вы '.$action[1].' понравились.';
      mysql_query("INSERT INTO `jurnal` SET
      `user` = '".$user['id']."',
      `outuser` = '".$u['id']."',
      `text` = '$text',
      `time` = '".time()."',
      `new` = '1'
      ");
	  } else {
	  $likes = '<a href = "page.php?id='.$user['id'].'&likes=1"><font color = "red">(+1)</font></a>';
	  }
   }
}

echo '<img src = "img/like.png" title = "Привлекательность"> '.$user['likes'].' '.$likes.' | <img src = "image/rating.png" title = "Рейтинг"> '.$user['rating'].' | <img src = "image/balanse.png" title = "Деньги"> '.$user['money'].'';

  
   
   $req = mysql_query("SELECT * FROM `garems_users` WHERE `id` = '".$user['id']."' LIMIT 1");
   if(mysql_num_rows($req)){
   $garem_user = mysql_fetch_assoc($req);
   if($garem_user['garem']){
   echo '<br><img src = "img/garems.gif"> В гареме у <a href = "page.php?id='.$garem_user['garem'].'">'.login($garem_user['garem']).'</a>';
   }
 echo '</div>';
   }
   //Если принадлежит пользователю
   if($u['id'] == $user['id']){
   //Проверяем не на дуэли ли
   $req = mysql_query("SELECT * FROM `duels_list` WHERE (`user1` = '".$user['id']."' or `user2` = '".$user['id']."') and `time_end` > '".time()."' LIMIT 1");
   if(mysql_num_rows($req)){
   $duel = mysql_fetch_assoc($req);
   if($duel['user1'] == $user['id']) $protiv = $duel['user2']; else $protiv = $duel['user1'];
   echo '<img src = "img/duels.gif"> Сейчас на <a href = "duels.php?act=view&id='.$user['id'].'">дуэли</a> против <a href = "page.php?id='.$protiv.'">'.login($protiv).'</a>';
   }
      $count_photo = mysql_result(mysql_query("SELECT COUNT(*) FROM `users_photo` WHERE `user` = '".$user['id']."'"), 0);
	 
	  
   	  //############################## Вывод подарков ##############################
	  $c_gifts = mysql_result(mysql_query("SELECT COUNT(*) FROM `gifts_users` WHERE `user` = '".$user['id']."'"), 0);           
if($c_gifts > 0){
      echo ' <div class = "title2"><b>Подарки пользователя</b></div><div class = "title">';   
 $result = mysql_query("SELECT * FROM `gifts_users` WHERE `user` = '".$user['id']."' ORDER BY `time` DESC LIMIT 0, 4");
				while($gift = mysql_fetch_assoc($result)){

	            echo '<a href = "gifts.php?act=view&id='.$gift['id'].'"><img src = "small_gifts/'.$gift['gift'].'.gif" width = "40"></a>';
echo '<a href = "gifts.php?act=list&id='.$user['id'].'"> >>></a></div>';                 
 }
		   
		   
           }
	  //######################################################################
	  
	  
   if($fa) $fa = '<font color = "red">(+'.$fa.')</font>'; else $fa = '';
   if($mn) $mn = '<font color = "red">(+'.$mn.')</font>'; else $mn = '';
   if($j) $j = '<font color = "red">(+'.$j.')</font>'; else $j = '';
   echo '<div class = "block_2"><a href = "profile.php"><img src="img/anketa.gif"> Анкета</a>';
$all_book = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `guestbook` WHERE `guestbook` = '".$id."'"), 0);

  echo '<br><br><a href = "guestbook.php?act=view&id='.$user['id'].'"><img src="img/guestbook.gif"> Гостевая';
if($all_book>0){
echo '( '.$all_book.' )';}else{echo '( 0 )';}
echo '</a>';
$cdiary = mysql_result(mysql_query("SELECT COUNT(*) FROM `diary_messages` WHERE `user` = '".$user['id']."'"), 0);
   echo '<br><br><a href = "diary.php?act=view&id='.$user['id'].'"><img src="img/diary.gif"> Дневники ('.$cdiary.')</a>';
   echo '<br><br><a href = "friends.php"><img src="img/friends.gif"> Друзья ('.$f.' | <font color = "green">'.$fo.'</font>) '.$fa.'</a>';
$cmicroblog = mysql_result(mysql_query("SELECT COUNT(*) FROM `microblog_messages` WHERE `user` = '".$user['id']."'"), 0);
   echo '<br><br><a href = "microblog.php"><img src="img/microblog.png"> Микроблог ('.$cmicroblog.')</a>';
 $cduels = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_list` WHERE `user1` = '".$user['id']."' OR `user2` = '".$user['id']."'"), 0);
   echo '<br><br><a href = "duels.php?act=view&id='.$user['id'].'"><img src="img/duels.gif"> Дуэли ('.$cduels.')</a>';
   $cgarems = mysql_result(mysql_query("SELECT COUNT(*) FROM `garems_users` WHERE `garem` = '".$user['id']."'"), 0);
   echo '<br><br><a href = "garems.php?act=view&id='.$user['id'].'"><img src="img/garems.png"> Гарем ('.$cgarems.')</a></div>';
   $cphotos = mysql_result(mysql_query("SELECT COUNT(*) FROM `photos_albums` WHERE `user` = '".$user['id']."'"), 0);
   $cphotos2 = mysql_result(mysql_query("SELECT COUNT(*) FROM `photos_photo` WHERE `user` = '".$user['id']."'"), 0);
   echo '<div class = "block_2"><a href = "photos.php"><img src="img/photos.gif"> Альбомы ('.$cphotos.' | '.$cphotos2.')</a></div>';
   $cgifts = mysql_result(mysql_query("SELECT COUNT(*) FROM `gifts_users` WHERE `user` = '".$user['id']."'"), 0);
   echo '<div class = "block_2"><a href = "gifts.php?act=list&id='.$user['id'].'"><img src="img/gifts.gif"> Подарки ('.$cgifts.')</a>';
   echo '<br><br><a href = "stat.php"><img src="img/stat.gif"> Статистика</a>';
   echo '<br><br><a href = "settings.php"><img src="img/settings.gif"> Мои настройки</a></div>';
   echo '<div class = "block_2"><a href = "dop.php"><img src="http://new-i09.spaces.ru//add.gif"><font color="green"> Дополнительные услуги</font></a></div>';
 
 

   //Если нет
   } else {
   
   //Проверяем не на дуэли ли
   $req = mysql_query("SELECT * FROM `duels_list` WHERE (`user1` = '".$user['id']."' or `user2` = '".$user['id']."') and `time_end` > '".time()."' LIMIT 1");
   if(mysql_num_rows($req)){
   $duel = mysql_fetch_assoc($req);
   if($duel['user1'] == $user['id']) $protiv = $duel['user2']; else $protiv = $duel['user1'];
   echo '<img src = "img/duels.gif"> Сейчас на <a href = "duels.php?act=view&id='.$user['id'].'">дуэли</a> против <a href = "page.php?id='.$protiv.'">'.login($protiv).'</a>';
   }

   
   //Скрываем информацию **************************************************
   if($user['priv_mypage']){
      //Друзьям
      if($user['priv_mypage'] == 1) {
         if($myfriend) $access = true; else$access = false;
      }
      //Только себе
      if($user['priv_mypage'] == 2) {
      $access = false;
      } 
   } else { $access = true; }
   
   if($access == true){
   
   	  //############################## Вывод подарков ##############################
	  $c_gifts = mysql_result(mysql_query("SELECT COUNT(*) FROM `gifts_users` WHERE `user` = '".$user['id']."'"), 0);
           if($c_gifts > 0){
echo ' <div class = "title2"><b>Подарки пользователя</b></div><div class = "title">';   
           $result = mysql_query("SELECT * FROM `gifts_users` WHERE `user` = '".$user['id']."' ORDER BY `time` DESC LIMIT 0, 4");
				while($gift = mysql_fetch_assoc($result)){
	            echo '<a href = "gifts.php?act=view&id='.$gift['id'].'"><img src = "small_gifts/'.$gift['gift'].'.gif" width = "30"></a>';
            
 }
echo '<a href = "gifts.php?act=list&id='.$user['id'].'">>>></a></div>';  
		   
           }
	  //######################################################################
   
   echo '<div class = "block_2"><a href = "profile.php?id='.$user['id'].'"><img src="img/anketa.gif"> Анкета</a>';
$all_book = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `guestbook` WHERE `guestbook` = '".$id."'"), 0);
  echo '<br><br><a href = "guestbook.php?act=view&id='.$user['id'].'"><img src="img/guestbook.gif"> Гостевая';
if($all_book>0){
echo '( '.$all_book.' )';}else{echo '( 0 )';}
echo '</a>';
 $cdiary = mysql_result(mysql_query("SELECT COUNT(*) FROM `diary_messages` WHERE `user` = '".$user['id']."'"), 0);
   echo '<br><br><a href = "diary.php?act=view&id='.$user['id'].'"><img src="img/diary.gif"> Дневники ('.$cdiary.')</a>';
   echo '<br><br><a href = "friends.php?act=write&id='.$user['id'].'"><img src="img/friends.gif"> Друзья ('.$f.' | <font color = "green">'.$fo.'</font>) '.$fa.'</a>';
$cmicroblog = mysql_result(mysql_query("SELECT COUNT(*) FROM `microblog_messages` WHERE `user` = '".$user['id']."'"), 0);
   echo '<br><br><a href = "microblog.php?act=write&id='.$user['id'].'"><img src="img/microblog.png"> Микроблог ('.$cmicroblog.')</a>';
 $cduels = mysql_result(mysql_query("SELECT COUNT(*) FROM `duels_list` WHERE `user1` = '".$user['id']."' OR `user2` = '".$user['id']."'"), 0);
   echo '<br><br><a href = "duels.php?act=view&id='.$user['id'].'"><img src="img/duels.gif"> Дуэли ('.$cduels.')</a>';
   $cgarems = mysql_result(mysql_query("SELECT COUNT(*) FROM `garems_users` WHERE `garem` = '".$user['id']."'"), 0);
   echo '<br><br><a href = "garems.php?act=view&id='.$user['id'].'"><img src="img/garems.png"> Гарем ('.$cgarems.')</a></div>';
   $cphotos = mysql_result(mysql_query("SELECT COUNT(*) FROM `photos_albums` WHERE `user` = '".$user['id']."'"), 0);
   $cphotos2 = mysql_result(mysql_query("SELECT COUNT(*) FROM `photos_photo` WHERE `user` = '".$user['id']."'"), 0);
   echo '<div class = "block_2"><a href = "photos.php?act=write&id='.$user['id'].'"><img src="img/photos.gif"> Альбомы ('.$cphotos.' | '.$cphotos2.')</a></div>';
   $cgifts = mysql_result(mysql_query("SELECT COUNT(*) FROM `gifts_users` WHERE `user` = '".$user['id']."'"), 0);
   echo '<div class = "block_2"><a href = "gifts.php?act=list&id='.$user['id'].'"><img src="img/gifts.gif"> Подарки ('.$cgifts.')</a>';
   echo '<br><br><a href = "stat.php?act=write&id='.$user['id'].'"><img src="img/stat.gif"> Статистика</a>';
   echo '</div>';
   

echo '<div class="title">';
   echo '<img src = "img/mail.gif"> <a href = "mail.php?act=write&id='.$user['id'].'">Написать сообщение</a><br/>';
   
   //Проверяем не друг ли
   $myfriend = mysql_num_rows(mysql_query("SELECT * FROM `friends` WHERE `user` = '".$u['id']."' and friend = '".$user['id']."' LIMIT 1"));
   if($myfriend)
   echo '<img src = "img/friends.gif"> <a href = "friends.php?act=delete&id='.$user['id'].'">Убрать из друзей</a><br/>';
   else echo '<img src = "img/friends.gif"> <a href = "friends.php?act=adding&id='.$user['id'].'">Добавить в друзья</a><br/>';
   echo '<img src = "img/gifts.gif"> <a href = "gifts.php?iduser='.$user['id'].'">Подарить подарок</a><br/>';
   echo '<img src = "image/rating.png"> <a href = "rating.php?id='.$user['id'].'">Поднять</a><br/>';
   if(!$duel['id']) {
   $req = mysql_query("SELECT * FROM `duels_list` WHERE (`user1` = '".$u['id']."' or `user2` = '".$u['id']."') and `time_end` > '".time()."' LIMIT 1");
   if(!mysql_num_rows($req)){
   echo '<img src = "img/duels.gif"> <a href = "duels.php?act=add&id='.$user['id'].'">Вызвать на дуэль</a><br/>';
   }
   }
   
   if($garem_user['garem'] != $u['id'] && $user['sex'] != $u['sex']) echo '<img src = "img/garems.gif"> <a href = "garems.php?act=add&id='.$user['id'].'">Украсть в гарем</a><br/>';
   
   echo '</div>';
   
   } else {
echo '</div>';
   echo '<div class = "action"> Пользователь ограничивает круг лиц, которые могут просматривать эту информацию. </div>';
echo '<div class="action">';
   echo '<img src = "img/mail.gif"> <a href = "mail.php?act=write&id='.$user['id'].'">Написать сообщение</a><br/>';
echo '<img src = "img/friends.gif"> <a href = "friends.php?act=adding&id='.$user['id'].'">Добавить в друзья</a><br/>';
echo '<img src = "img/gifts.gif"> <a href = "gifts.php?iduser='.$user['id'].'">Подарить подарок</a><br/>';
   echo '<img src = "image/rating.png"> <a href = "rating.php?id='.$user['id'].'">Поднять</a><br/>';

  
   
   }


 
   
   
   }
   
echo '</div>';
include 'foot.php';

?>