<?php

define('_IN_JOHNCMS', 1);
$headmod = 'anketa';
require_once('../incfiles/core.php');
if (!$user_id) {
$link='' . $home . '/login.php';
header("Location: $link");exit;}
if ($id && $id != $user_id) {
    // Если был запрос на юзера, то получаем его данные
    $req = mysql_query("SELECT * FROM `users` WHERE `id` = '$id' LIMIT 1");
    if (mysql_num_rows($req)) {
        $user = mysql_fetch_assoc($req);
        $textl = '' . $copyright . ' - Анкета: ' . $user['name'];
    } else {
        require_once('../incfiles/head.php');
        echo display_error('Такого пользователя не существует');
        require_once("../incfiles/end.php");
        exit;
    }
} else {
    $id = false;
    $textl = '' . $copyright . ' - Личная анкета';
    $user = $datauser;
}

require_once('../incfiles/head.php');

$sql_ip = mysql_query("select * from prosm where kto = '".$ipl."' AND user_id = '".$id."'");
$row_ip = mysql_fetch_assoc($sql_ip);
if(empty($row_ip['user_id'])) {
    mysql_query("INSERT INTO prosm SET `user_id` = '".$id."', `kto` = '".$ipl."', `data` = '".date("y.m.d - H:i:s")."'");
    mysql_query("UPDATE `users` SET `prosm` = (`prosm` + 1) where id = '".$id."'");
}
echo '<div class="phdr"><b>' . ($id ? 'Страница ' . $user['name'] . '' : 'Страница ' . $user['name'] . ' [это Вы]') . '</b></div>';
if ($user['dayb'] == $day && $user['monthb'] == $mon) {
    echo '<div class="gmenu">ИМЕНИНЫ!!!</div>';
}

echo '<div class="gmenu"><p>';
echo '<b>' . $user['name'] . '</b> ID: ' . $user['id'] . ' ';
if ($realtime > $user['lastdate'] + 300) {
    $lastvisit = date("d.m.Y в H:i", $user['lastdate']);
    if (isset($lastvisit))
    echo ' <span class="gray">[Посл. визит: ' . $lastvisit . ']</span>';
} else {
    echo ' <span class="gray">[Сейчас онлайн]</span>';
}
  echo '<div class="gmenu">';
  $medal = $user['postforum'];
if ($medal >= 500 AND $medal < 1000) {$medal2 = ' <img src = "../images/medal/3.gif" />';}
if ($medal >= 1000 AND $medal < 1500) {$medal2 = ' <img src = "../images/medal/3.gif" /> <img src = "../images/medal/2.gif" />';}
if ($medal >= 1500) {$medal2 = ' <img src = "../images/medal/3.gif" /> <img src = "../images/medal/2.gif" /> <img src = "../images/medal/1.gif" />';}
echo $medal2;
echo '</div>';
if(empty($id)){
    $red_st = ' [<a href="' . $home . '/str/statusik.php">изм.</a>]'; 
    if(!empty($user['statusik'])){
        $red_st .= '[<a href="' . $home . '/str/statusik.php?item=del">x</a>]';
    }
}
if(!empty($user['statusik']) && $user['statusik_img'] !== '1'){
    $img = '<img src="/images/st/' .  $user['statusik_img'] .'.gif" /> ';
}
if (!empty($user['statusik'])){
    echo '<span class="gray">Статус: </span> ' . $img . $user['statusik'] . $red_st . ' <br />';
	} else {
    echo '<span class="gray">Статус: </span>Нет статуса ' . $red_st .'<br />';
}
echo '';

// Показываем фотографию (если есть)
$link = '';
if (file_exists(('../files/photo/' . $user['id'] . '_small.jpg'))) {
    echo '<p><a href="../files/photo/' . $user['id'] . '.jpg"><img src="../files/photo/' . $user['id'] . '_small.jpg" alt="' . $user['name'] . '" border="0" /></a></p>';
	echo '' . ($id ? '' : '<small><a href="' . $home . '/str/my_images.php?act=up_photo&amp;id=' . $user['id'] . '">Изменить</a> / <a href="' . $home . '/str/my_data.php?id=' . $user['id'] . '&amp;delphoto">Удалить</a></small>') . '';
} else {
    echo '<p><img src="../images/no_photo.gif" alt="Нет фото" /></p>
	' . ($id ? '' : '<small><a href="' . $home . '/str/my_images.php?act=up_photo&amp;id=' . $user['id'] . '">Выгрузить фото</a></small>') . '';
}

echo '</p></div>';
echo '<div class="menu">';
if ($rights >= 1 && $rights >= $user['rights']) {
    echo '<span class="gray">UserAgent:</span> ' . $user['browser'] . '<br />';
    echo '<span class="gray">Адрес IP:</span> <a href="' . $home . '/' . $admp . '/index.php?act=usr_search_ip&amp;ip=' . $user['ip'] . '">' . long2ip($user['ip']) . '</a><br />';
}
echo '</div>';

// Блок Кармы
if ($set_karma['on']) {
    echo '<div>';
    $exp = explode('|', $user['plus_minus']);
    if ($exp[0] > $exp[1]) {
        $karma = $exp[1] ? ceil($exp[0] / $exp[1]) : $exp[0];
        $images = $karma > 10 ? '2' : '1';
    } else if ($exp[1] > $exp[0]) {
        $karma = $exp[0] ? ceil($exp[1] / $exp[0]) : $exp[1];
        $images = $karma > 10 ? '-2' : '-1';
    } else {
        $images = 0;
    }
    echo '<table  width="100%"><tr><td>';
    echo '<img src="../images/rating.gif" width="18" height="12" alt="-" /> <b><a href="' . $home . '/str/karma.php?id=' . $id . '">Рейтинг:</a> ' . $user['karma'] . '%</b><div>';
    if ($id) {
        if (!$datauser['karma_off'] && (!$user['rights'] || ($user['rights'] && !$set_karma['adm'])) && $user['ip'] != $datauser['ip']) {
            $sum = mysql_result(mysql_query("SELECT SUM(`points`) FROM `karma_users` WHERE `user_id` = '$user_id' AND `time` >= '" . $datauser['karma_time'] . "'"), 0);
            $count = mysql_result(mysql_query("SELECT COUNT(*) FROM `karma_users` WHERE `user_id` = '$user_id' AND `karma_user` = '$id' AND `time` > '" . ($realtime - 86400) . "'"), 0);
            if ($datauser['postforum'] >= $set_karma['forum'] && $datauser['total_on_site'] >= $set_karma['karma_time'] && ($set_karma['karma_points'] - $sum) > 0 && !$count) {
             echo '<a href="' . $home . '/str/karma.php?act=user&amp;id=' . $id . '"><small>Отдать голос за ' . $user['name'] . '</small></a>';
            }
        }
    } else {
        $total_karma = mysql_result(mysql_query("SELECT COUNT(*) FROM `karma_users` WHERE `karma_user` = '$user_id' AND `time` > " . ($realtime - 86400)), 0);
        if ($total_karma > 0)
            echo '<br /><a href="' . $home . '/str/karma.php?act=new">Новые голоса</a> (' . $total_karma . ')';
    }
    echo '</div></td></tr></table></div>';
}
// Блок подарков
$sql_id = $id ? $id : $user_id;
$total_present = mysql_result(mysql_query("SELECT COUNT(*) FROM `present` WHERE `podarili`='$sql_id'"), 0);
if ($id) {
echo '<div class="menu"><p><img src="../images/present.gif" width="12" height="12" alt="-" /><b>&nbsp;<a href="' . $home . '/present/user/' . $sql_id. ',0">Подарки</a>';
$k_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `present` WHERE `podarili`='$id'"), 0);
echo " ($k_p)</b><br />"; }else{
$k_p = mysql_result(mysql_query("SELECT COUNT(*) FROM `present` WHERE `podarili`='$user_id'"), 0);
echo '<div class="menu"><p><img src="../images/present.gif" width="12" height="12" alt="-" /><b>&nbsp;<a href="' . $home . '/present/user/' . $sql_id. ',0">Мои подарки</a>';
echo " ($k_p)</b><br />";
}

if ($id) {
$colmes = mysql_result(mysql_query("SELECT COUNT(*) FROM `present` WHERE `podarili`='$id'"), 0);
if ($colmes) {
                $podd = mysql_query("SELECT `present`.*, `users`.`name` AS `nikname` FROM `present` LEFT JOIN `users` ON `present`.`podaril` = `users`.`id` WHERE `present`.`podarili`='$id' ORDER BY `present`.`vr` DESC LIMIT 3");
                while ($res = mysql_fetch_array($podd)) {
                    echo ($i % 2) ? '' : '';
                    echo '<img src="' . $home . '/images/present/' . $res['present'] . '" width="48" height="48" alt="Подарок" />';
                    ++$i;
                }
            }
			
}else{
$colmes = mysql_result(mysql_query("SELECT COUNT(*) FROM `present` WHERE `podarili`='$user_id'"), 0);
if ($colmes) {
                $podd = mysql_query("SELECT `present`.*, `users`.`name` AS `nikname` FROM `present` LEFT JOIN `users` ON `present`.`podaril` = `users`.`id` WHERE `present`.`podarili`='$user_id' ORDER BY `present`.`vr` DESC LIMIT 3");
                while ($res = mysql_fetch_array($podd)) {
                    echo ($i % 2) ? '' : '';
                    echo '<img src="' . $home . '/images/present/' . $res['present'] . '" width="48" height="48" alt="Подарок" />';
                    ++$i;
                }
            }

}
if ($colmes==0) {
echo '<div>Нет подарков</div>';}
$sql_id = $id ? $id : $user_id;
if ($id && $id != $user_id) {
  echo '<div><small><a href="' . $home . '/present/add/1/' . $sql_id . ',0">Сделать подарок</a></small></div>';
}
  echo '</p></div>';

// Личные данные
echo '<div class="gmenu">';
$out = '';
$req = mysql_query("select * from `gallery` where `type`='al' and `user`=1 and `avtor`='" . $user['name'] . "' LIMIT 1");
if (mysql_num_rows($req)) {
    $res = mysql_fetch_array($req);
    $out .= '<li><a href="../gallery/index.php?id=' . $res['id'] . '">Личный альбом</a></li>';
}
if (!empty($user['imname']))
    $out .= '<span class="gray">Имя:</span> ' . $user['imname'] . '<br />';
	 echo '<span class="gray">Баллов:</span> ' . (empty($id) ? mysql_result(mysql_query("select `bals` from `users` where id='$user_id'"),0) : mysql_result(mysql_query("select `bals` from `users` where id='$id'"),0)) . '  <br />';
	if ($user['rights']) {
    echo ' ';
    $rank = array (
        1 => 'Килер',
        2 => 'Модератор',
        3 => 'Модератор',
        4 => 'Модератор',
        5 => 'Модератор',
        6 => 'Старший модерератор',
        7 => 'Администратор',
        9 => 'Создатель'
    );
    echo '<span class="gray">Должность:</span> ' . $rank[$user['rights']] . '';
    echo '<br />';
}
	echo '' . ($user['sex'] == 'm' ? '<span class="gray">Пол:</span> Мужской' : '<span class="gray">Пол:</span> Женский') . '  <br />';
if (!empty($user['age']))
    $out .= '<span class="gray">Возраст:</span> ' . $user['age'] . '<br />';
if (!empty($user['live']))
    $out .= '<span class="gray">Город:</span> ' . $user['live'] . '<br />';
if (!empty($user['about'])) 
    $out .= '<span class="gray">О себе:</span> ' . smileys(tags($user['about'])) . '<br />';
if (!empty($user['sp']) && $user['sp'] !== 0 && $user['sp'] !== '-'){ 
$row = mysql_fetch_assoc(mysql_query("select * from users WHERE `id` = '".$user['id']."'"));
$sp_ar = array("m" => array(1 => "Не женат", "Есть подруга", "Помолвлен", "Женат", "Все сложно", "В активном поиске"), "zh" => array(1 => "Не замужем", "Есть друг", "Помолвлена", "Замужем", "Все сложно", "В активном поиске"), "my" => array(1 => "Не женат", "Встречаюсь с ", "Помолвлен с ", "Женат на ", "Все сложно с ", "В активном поиске"), "zhy" => array(1 => "Не замужем", "Встречаюсь с ", "Помолвлена с ", "Замужем на ", "Все сложно с ", "В активном поиске"));
    if($row['sp'] == 0){
        $ar = false;
        $kto =false;
    }
    elseif($row['sp'] == 1 OR $row['sp'] == 6){
        $ar = $row['sex'];
        $kto = false;
    }
    elseif($row['name'] == mysql_result(mysql_query("select sp_user from users where name = '".$row['sp_user']."' limit 1"),0)){
        $ar = $row['sex'].'y';
        $kto = '<a href="anketa.php?id='.mysql_result(mysql_query("select id from users where name = '".$row['sp_user']."' limit 1"),0).'"><b>'.mysql_result(mysql_query("select name from users where name = '".$row['sp_user']."' limit 1"),0).'</b></a>';
    }
    else {
        $ar = $row['sex'];
        $kto = ' ('.$row['sp_user'].')';
    }
    if(!empty($id)) $kto = false;
    $out .= '<span class="gray">Семейное положение: </span>'.$sp_ar[$ar][$row['sp']]."<br />";
}
if (!empty($out)) {
    echo '<p>';
    echo $out;
    echo '</p>';
}
$out = '';
if (!empty($user['mibile']))
    $out .= '<span class="gray">Тел. номер:</span> ' . $user['mibile'] . '<br />';
if (!empty($user['mail']) && (($id && $user['mailvis']) || !$id || $rights >= 7)) {
    $out .= '<span class="gray">E-mail:</span> ' . $user['mail'];
    $out .= ($user['mailvis'] ? '' : '<span class="gray"> [скрыт]</span>') . '<br />';
}
if (!empty($user['icq']))
    $out .= '<span class="gray">ICQ:</span>&nbsp;' . $user['icq'] . '<br />';
if (!empty($user['skype']))
    $out .= '<span class="gray">Skype:</span>&nbsp;' . $user['skype'] . '<br />';
if (!empty($user['jabber']))
    $out .= '<span class="gray">Jabber:</span>&nbsp;' . $user['jabber'] . '<br />';
if (!empty($user['www']))
    $out .= '<span class="gray">Сайт:</span> ' . tags($user['www']) . '<br />';
if (!empty($out))
{
    echo '<p>';
    echo $out;
    echo '</p>';
}
// Статистика
echo '<p>';
echo '<span class="gray">' . ($user['sex'] == 'm' ? 'Зарегистрирован' : 'Зарегистрирована') . ':</span> ' . date("d.m.Y", $user['datereg']) . '<br />';
echo '<span class="gray">' . ($user['sex'] == 'm' ? 'Пробыл' : 'Пробыла') . ' на сайте:</span> ' . timecount($user['total_on_site']) . '<br />';
if(empty($id)) $prosm = mysql_result(mysql_query("select `prosm` from `users` where id='$user_id'"),0);
else $prosm = mysql_result(mysql_query("select `prosm` from `users` where id='$id'"),0);
echo 'Страница просмотрена: ' . $prosm . ' раз(а)';
// Если были нарушения, показываем ссылку на их историю
$ban = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_ban_users` WHERE `user_id` = '" . $user['id'] . "'"), 0);
if ($ban)
    echo '<a href="users_ban.php' . ($id && $id != $user_id ? '?id=' . $user['id'] : '') . '">Нарушения</a>&nbsp;<span class="red">(' . $ban . ')</span><br />';
echo '</p>';
//Добавляем личный блог
echo '</div><div class="menu">';

echo '<img src="' . $home . '/images/act2.gif" width="9" height="9" alt="-" /> <!--img src="/foto/tpl/img/foto.png" alt="" /--> <a href="/foto/index.php?mod=user_albom&amp;id='.$user['id'].'">' . ($id ? 'Фотоальбомы ' . $user['name'] . '</a> ['.mysql_result(mysql_query("SELECT COUNT(*) FROM `foto_albom` WHERE id_user = '".$user['id']."'"), 0).']' : 'Мои фотоальбомы</a> ['.mysql_result(mysql_query("SELECT COUNT(*) FROM `foto_albom` WHERE id_user = '".$user['id']."'"), 0).']') . '<br />';
$usfiles =  mysql_result(mysql_query("SELECT COUNT(*) FROM `zc_vsetkefiles` WHERE `user_id`='".$user['id']."'"), 0);
echo '<img src="' . $home . '/images/act2.gif" width="9" height="9" alt="-" /> <a href="' . $home . '/down/files.php?id='.$user['id'].'">' . ($id ? 'Файлы ' . $user['name'] . '</a> [' . $usfiles . ']' : 'Мои файлы</a> [' . $usfiles . ']') . '<br />';
$friends = mysql_result(mysql_query("SELECT COUNT(*) FROM `friends` WHERE `user`='" . $user['id'] . "' AND `preg`='1';"), 0);
echo '<img src="' . $home . '/images/act2.gif" width="9" height="9" alt="-" /> <a href="' . $home . '/str/friends.php?id='.$user['id'].'">' . ($id ? 'Друзья ' . $user['name'] . '</a> [' . $friends . ']' : 'Мои друзья</a> [' . $friends . ']') . '<br />';
echo '<img src="' . $home . '/images/act2.gif" width="9" height="9" alt="-" /> <a href="' . $home . '/blogs/blogs.php' . ($id ? '?id=' . $id : '') . '">' . ($id ? 'Дневник ' . $user['name'] : 'Мой дневник') . '</a><br />';
$stt = mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_users` WHERE `user_wall`='$user_id'"), 0);
$sttt = mysql_result(mysql_query("SELECT COUNT(*) FROM `wall_users` WHERE `user_wall`='$id'"), 0);
echo '<img src="' . $home . '/images/act2.gif" width="9" height="9" alt="-" /> <a href="' . $home . '/str/wall_user.php?id=' . $id . '">' . ($id ? 'Стена ' . $user['name'] . '</a> [' . $sttt . ']' : 'Моя стена</a> [' . $stt . ']') . '<br />';
if ($id && $id != $user_id) {
    echo '';
	
	  // Друзья
    $friends = mysql_query("SELECT * FROM `friends` WHERE `user`='" . $user_id . "' AND `to`='" . $user['id'] . "';");
    $friend = mysql_num_rows($friends);
    if ($friend != 1)
        echo "<img src='" . $home . "/images/act2.gif' width='9' height='9' alt='-' /> <a href='" . $home . "/str/friends.php?act=add&amp;id=" . $id . "'>Добавить в друзья</a><br/>";
    else
        echo "<img src='" . $home . "/images/act2.gif' width='9' height='9' alt='-' /> <a href='" . $home . "/str/friends.php?act=del&amp;id=" . $id . "'>Удалить из друзей</a><br/>";
	
    // Контакты
    $contacts = mysql_query("select * from `privat` where me='" . $login . "' and cont='" . $user['name'] . "'");
    $conts = mysql_num_rows($contacts);
    if ($conts != 1)
        echo "<img src='" . $home . "/images/act2.gif' width='9' height='9' alt='-' /> <a href='" . $home . "/str/cont.php?act=edit&amp;id=" . $id . "&amp;add=1'>Добавить в контакты</a><br/>";
    else
        echo "<img src='" . $home . "/images/act2.gif' width='9' height='9' alt='-' /> <a href='" . $home . "/str/cont.php?act=edit&amp;id=" . $id . "'>Удалить из контактов</a><br/>";

    echo '<img src="' . $home . '/images/act2.gif" width="9" height="9" alt="-" /> <a href="' . $home . '/str/pradd.php?act=write&amp;adr=' . $user['id'] . '">Написать в приват</a><br />';
}
echo '<img src="' . $home . '/images/act2.gif" width="9" height="9" alt="-" /> <a href="' . $home . '/str/my_stat.php?id=' . $user['id'] . '">' . ($id ? 'С' : 'Моя с') . 'татистика</a><br />';
echo '</div>';

echo '<div class="phdr">' . (!$id || $id == $user_id || $rights >= 7 ? '<a href="' . $home . '/str/my_data.php' . ($id ? '?id=' . $id : '') . '">Редактировать</a>' : '');
if ($id && !$user['immunity'] && $id != $user_id && $rights > $user['rights']) {
    if ($rights >= 7)
        echo ' | ';
    echo '<a href="' . $home . '/str/users_ban.php?act=ban&amp;id=' . $user['id'] . '">Банить</a>';
    if ($rights >= 7)
        echo ' | <a href="' . $home . '/' . $admp . '/index.php?act=usr_del&amp;id=' . $user['id'] . '">Удалить</a><br/>';
}

echo '</div>';

require_once('../incfiles/end.php');
?>