<?php

/**
 * @package     JohnCMS
 * @link        http://johncms.com
 * @copyright   Copyright (C) 2008-2011 JohnCMS Community
 * @license     LICENSE.txt (see attached file)
 * @version     VERSION.txt (see attached file)
 * @author      http://johncms.com/about
 */

define('_IN_JOHNCMS', 1);

require('../incfiles/core.php');
$lng_profile = core::load_lng('profile');

/*
-----------------------------------------------------------------
Закрываем от неавторизованных юзеров
-----------------------------------------------------------------
*/
if (!$user_id) {
    require('../incfiles/head.php');
    echo functions::display_error($lng['access_guest_forbidden']);
    require('../incfiles/end.php');
    exit;
}

/*
-----------------------------------------------------------------
Получаем данные пользователя
-----------------------------------------------------------------
*/
$user = functions::get_user($user);
if (!$user) {
    require('../incfiles/head.php');
    echo functions::display_error($lng['user_does_not_exist']);
	
    require('../incfiles/end.php');
    exit;
}

/*
-----------------------------------------------------------------
Переключаем режимы работы
-----------------------------------------------------------------
*/
$array = array(
    'activity'  => 'includes/profile',
    'ban'       => 'includes/profile',
    'edit'      => 'includes/profile',
	'events'    => 'includes/profile',
	'events_set'=> 'includes/profile',
    'images'    => 'includes/profile',
    'info'      => 'includes/profile',
    'ip'        => 'includes/profile',
    'guestbook' => 'includes/profile',
    'karma'     => 'includes/profile',
    'office'    => 'includes/profile',
	//'status' => 'includes/profile', 
    'password'  => 'includes/profile',
    'reset'     => 'includes/profile',
    'settings'  => 'includes/profile',
    'stat'      => 'includes/profile',
    'friends'   => 'includes/profile',
	'link_history' => 'includes/profile'
);
$path = !empty($array[$act]) ? $array[$act] . '/' : '';
if (array_key_exists($act, $array) && file_exists($path . $act . '.php')) {
    require_once($path . $act . '.php');
} else {
    /*
    -----------------------------------------------------------------
    Анкета пользователя
    -----------------------------------------------------------------
    */
    $headmod = 'profile,' . $user['id'];
    $textl = $lng['profile'] . ': ' . htmlspecialchars($user['name']);
    require('../incfiles/head.php');
    echo '<div class="phdr"><b>' . ($user['id'] != $user_id ? $lng_profile['user_profile'] : $lng_profile['my_profile']) . '</b></div>';



    // Меню анкеты
    $menu = array();
    if ($user['id'] == $user_id || $rights == 9 || ($rights == 7 && $rights > $user['rights'])) {
        $menu[] = '<a href="profile.php?act=edit&amp;user=' . $user['id'] . '">' . $lng['edit'] . '</a>';
    }
    if ($user['id'] != $user_id && $rights >= 7 && $rights > $user['rights']) {
        $menu[] = '<a href="' . $set['homeurl'] . '/' . $set['admp'] . '/index.php?act=usr_del&amp;id=' . $user['id'] . '">' . $lng['delete'] . '</a>';
    }
    if ($user['id'] != $user_id && $rights > $user['rights']) {
        $menu[] = '<a href="profile.php?act=ban&amp;mod=do&amp;user=' . $user['id'] . '">' . $lng['ban_do'] . '</a>';
    }
    if (!empty($menu)) {
        echo '<div class="topmenu">' . functions::display_menu($menu) . '</div>';
    }

    //Уведомление о дне рожденья
    if ($user['dayb'] == date('j', time()) && $user['monthb'] == date('n', time())) {
        echo '<div class="gmenu">' . $lng['birthday'] . '!!!</div>';
    }

    // Информация о юзере
    $arg = array(
        'lastvisit' => 1,
        'iphist'    => 1,
        'header'    => '<b>ID:' . $user['id'] . '</b>'
    );

    if ($user['id'] != core::$user_id) {
        $arg['footer'] = '<span class="gray">' . core::$lng['where'] . ':</span> ' . functions::display_place($user['id'], $user['place']);
    }

//gift sovga tayyorlash
$lng_gifts = core::load_lng('gifts');
    $gift = mysql_fetch_assoc(mysql_query("SELECT * FROM `users_gifts` WHERE `user_id` = '" . $user['id'] . "' ORDER BY `id` DESC LIMIT 1"));
if($gift)
{
$fromw = functions::get_user($gift['from_id']);
if($user['id'] == $user_id)
{
$alt = $lng_gifts['from'] . ' ' . $fromw['name'] . (!empty($gift['text']) ? ': ' . $gift['text'] : '');
}
else
{
if($gift['type'] == 0)
$alt = $lng_gifts['from'] . ' ' . $fromw['name'] . (!empty($gift['text']) ? ': ' . $gift['text'] : '');
else
$alt = $lng_gifts['privat'];
}
echo '<div style="float: right; margin-right: 5px; margin-top: 5px;"><a href="/gifts/?user=' . $user['id'] . '"><img src="/images/gifts/'.$gift['image'].'" style="float: right;" alt="' . $alt . '" title="' . $alt . '"  width="64" height="64" /></a></div>';
}
else
{
echo '<div style="float: right; margin-right: 5px; margin-top: 5px;"><a href="/gifts/?user=' . $user['id'] . '"><img src="/images/gift.png" style="float: right;" alt="' . $lng_gifts['send'] . '" title="' . $lng_gifts['send'] . '"  width="64" height="64" /></a></div>';
}
//gift sovga tayyorlash tugashi

    echo '<div class="user"><p>' . functions::display_user($user, $arg) . '</p></div>';
    // Если юзер ожидает подтверждения регистрации, выводим напоминание
    if ($rights >= 7 && !$user['preg'] && empty($user['regadm'])) {
        echo '<div class="rmenu">' . $lng_profile['awaiting_registration'] . '</div>';
		
    }

/////////STATUS boshi///////////

$bender_statuslari=mysql_result(mysql_query("SELECT COUNT(*) FROM `bender_status` WHERE `id_user`='$user[id]'"),0);
$s=mysql_query("SELECT * FROM `bender_status` WHERE `id_user` = '$user[id]' ORDER BY `time` DESC  LIMIT 1");
$sts_qiymati=mysql_result(mysql_query("SELECT COUNT(*) FROM `bender_status` where `id_user`=$user[id]"),0);


if ($sts_qiymati==0) {
if ($user['id'] == $user_id) {
echo '<div class="status_t"><form action="'.$home.'/status/?bender=status_saqlash" method="post">
			<input type="name" name="name" maxlength="150" size="18" class="anput"/><input value="    +    " type="submit"/></form>
			</div>';
}}

while ($sts = mysql_fetch_assoc($s)){
if ($user['id']==$user_id) {
echo '<div class="status_t"><form action="'.$home.'/status/?bender=status_saqlash" method="post">
			<input type="name" name="name" maxlength="150" size="18" class="anput"/><input value="    +    " type="submit"/></form>
			</div>';
			
echo '<div class="status">'.functions::checkout($sts[name]).'<font style="font-size:11px; color:gray;">&#160;&#160;&#160;'.functions::display_date($sts['time']).'</font></div>';
} else {
echo '<div class="status">'.functions::checkout($sts[name]).'<font style="font-size:11px; color:gray;">&#160;&#160;&#160;'.functions::display_date($sts['time']).'</font></div>';
}
require_once('closed.php');
$sts_izoh=mysql_num_rows(mysql_query("select * from bender_status_kom where type='status' and id_kogo='$sts[id]'"));
echo '<div class="status_p"><a href="/status/?bender=izoh&amp;id_kim='.$user['id'].'&amp;id_sts='.$sts[id].'"><img src="/images/status/fikr.png" /> '.$sts_izoh.'</a>';
$ajoyib_sts=mysql_query("SELECT * FROM `bender_status_klass` WHERE `type`='status' AND `zakogo`='$sts[id]' AND `kto`='$user_id' LIMIT 1");
$sts1=mysql_query("select * from bender_status where id='$sts[id]' limit 1");
$zor_sts=mysql_fetch_array($sts1);
if($user[id] != $user_id) {
if($user_id and mysql_num_rows($ajoyib_sts)==0 and $user_id!=$user['id']){
echo ' &bull;
<a href="/status/?bender=view&amp;id_kim='.$user['id'].'&amp;id_sts='.$sts[id].'">
<img src="/images/status/klass.png" />'.$zor_sts['ajoyib'].' </a> &bull; <a href="/status/?bender=klass&amp;id_kim='.$user['id'].'&amp;id_sts='.$sts[id].'">Klass!</a>';
}else{
$minus='1';
$ok_status=$zor_sts[ajoyib]-$minus;
echo ' &bull;
<a href="/status/?bender=view&amp;id_kim='.$user['id'].'&amp;id_sts='.$sts[id].'">
<img src="/images/status/klass.png" />Siz va '.$ok_status.'</a>';
}
}else{
echo ' &bull;
<a href="/status/?bender=view&amp;id_kim='.$user['id'].'&amp;id_sts='.$sts[id].'">
<img src="/images/status/klass.png" />'.$zor_sts['ajoyib'].' ta!</a>';
}
echo '</div>';
}
/////////STATUS oxiri///////////


echo '<div class="grey">'.$horozago.'</div>';
	//karmani o'rniga karmani qo'yish ham mumkin
	$req_p=mysql_query("SELECT * FROM `attitude` WHERE `vote`=1 AND `from_user`='".$user['id']."'");
	$count_plus=mysql_result(mysql_query("SELECT COUNT(*) FROM `attitude` WHERE `vote`=1 AND `from_user`='".$user['id']."'"), 0);
	$count_minus=mysql_result(mysql_query("SELECT COUNT(*) FROM `attitude` WHERE `vote`=2 AND `from_user`='".$user['id']."'"), 0);
	$rait=$count_plus-$count_minus;
	$color='green';
	if ($rait<0)$color='red';
	echo '<div class="gmenu">' . functions::image('label.png') . '<a href="attitude.php?id='.$user['id'].'">Foydalanuvchi reytingi:</a> <font color="'.$color.'">'.$rait.'</font> (<a href="attitude.php?act=plus&amp;id='.$user['id'].'"><font color="green">'.$count_plus.'</font></a> / <a href="attitude.php?act=plus&amp;id='.$user['id'].'"><font color="red">'.$count_minus.'</font></a>)</div>';

	
	// Вывод медалей
    $rank1 = '<img src="/images/rank/1.gif" alt="*"/>';
    $rank2 = '<img src="/images/rank/2.gif" alt="*"/>'; 
    $rank3 = '<img src="/images/rank/3.gif" alt="*"/>';
    $rank4 = '<img src="/images/rank/4.gif" alt="*"/>';
    $rank6 = '<img src="/images/rank/6.gif" alt="*"/>';
    $rank7 = '<img src="/images/rank/7.gif" alt="*"/>';
    $rank8 = '<img src="/images/rank/8.gif" alt="*"/>';
    $rank9 = '<img src="/images/rank/9.png" alt="*"/>';
    $rank10 ='<img src="/images/rank/10.gif" alt="*"/>';
    
    
  
    
    if($user['postforum']>=0 && $user['postforum']<=0) 
    echo '<div class="menu">Medali yo\'q</div>'; 
    if($user['postforum']>=1 && $user['postforum']<=50) 
    echo '<div class="menu">Medal: '.$rank1.'</div>'; 
    if($user['postforum']>=51 && $user['postforum']<=80) 
    echo '<div class="menu">Medallari: '.$rank1.''.$rank2.'</div>'; 
    if($user['postforum']>=81 && $user['postforum']<=100) 
    echo '<div class="menu">Medallari: '.$rank1.''.$rank2.''.$rank3.'</div>'; 
    if($user['postforum']>=101 && $user['postforum']<=150) 
    echo '<div class="menu">Medallari: '.$rank1.''.$rank2.''.$rank3.''.$rank4.'</div>'; 
    if($user['postforum']>=151 && $user['postforum']<=200) 
    echo '<div class="menu">Medallari: '.$rank1.''.$rank2.''.$rank3.''.$rank4.''.$rank5.'</div>'; 
    if($user['postforum']>=201 && $user['postforum']<=300) 
    echo '<div class="menu">Medallari: '.$rank1.''.$rank2.''.$rank3.''.$rank4.''.$rank5.''.$rank6.'</div>'; 
    if($user['postforum']>=301 && $user['postforum']<=400) 
    echo '<div class="menu">Medallari: '.$rank1.''.$rank2.''.$rank3.''.$rank4.''.$rank5.''.$rank6.''.$rank7.'</div>'; 
    if($user['postforum']>=401 && $user['postforum']<=550) 
    echo '<div class="menu">Medallari: '.$rank1.''.$rank2.''.$rank3.''.$rank4.''.$rank5.''.$rank6.''.$rank7.''.$rank8.'</div>'; 
     if($user['postforum']>=551 && $user['postforum']<=700) 
    echo '<div class="menu">Medallari: '.$rank1.''.$rank2.''.$rank3.''.$rank4.''.$rank5.''.$rank6.''.$rank7.''.$rank8.''.$rank9.'</div>'; 
    if($user['postforum']>=701 && $user['postforum']<=1000) 
    echo '<div class="menu">Medallari: '.$rank1.''.$rank2.''.$rank3.''.$rank4.''.$rank5.''.$rank6.''.$rank7.''.$rank8.''.$rank9.'</div>'; 
     if($user['postforum']>=1001 && $user['postforum']<=5000) 
    echo '<div class="menu">Medallari: '.$rank1.''.$rank2.''.$rank3.''.$rank4.''.$rank5.''.$rank6.''.$rank7.''.$rank8.''.$rank9.''.$rank10.'</div>';

// рейтинг
$rating = ($user['postforum'] + $user['postguest'] + $user['komm'] + $user['balans'] + $user['karma_plus']) / ($user['karma_minus'] + 100);
// рейтинг
	echo '<div class="menu"><img src="../users/img.php?img=' . $rating . '" alt="' . $rating . '" /></div>';
	echo '<div class="menu"><span style="color:red"><b>Рейтинг:</b></span> <b><span style="color:black">' . $rating . '</span></b></div>';
// баллы

echo '<div class="menu"><b><span style="color:red">Ball:</span></b> <b><span style="color:blue"></span></b> <b>'.$user['balans'].'</b> | <a href="perevod.php">Ball o\'tkazish</a> <span style="color:red"><b></b></span></div>';
		





	

    // Меню выбора
    $total_photo = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_album_files` WHERE `user_id` = '" . $user['id'] . "'"), 0);
    echo '' .
        '<div class="menu"><p>&#160;&#187;&#160;' .  '<a href="profile.php?act=info&amp;user=' . $user['id'] . '">' . $lng['information'] . '</a></div>' .
        '<div class="menu"><p>&#160;&#187;&#160;' .  '<a href="profile.php?act=activity&amp;user=' . $user['id'] . '">' . $lng_profile['activity'] . '</a></div>' .
        '<div class="menu"><p>&#160;&#187;&#160;' .  '<a href="profile.php?act=stat&amp;user=' . $user['id'] . '">' . $lng['statistics'] . '</a></div>';
    $bancount = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_ban_users` WHERE `user_id` = '" . $user['id'] . "'"), 0);

    if ($bancount) {
        echo '<div class="menu"><p>&#160;&#187;&#160;' .  '<a href="profile.php?act=ban&amp;user=' . $user['id'] . '">' . $lng['infringements'] . '</a> (' . $bancount . ')</div>';
    }

//gift sovga boshlanishi baza
$total_gifts = mysql_result(mysql_query("SELECT COUNT(*) FROM `users_gifts` WHERE `user_id`='{$user['id']}'"), 0);
//gift sovga tugashi baza
    $total_friends = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_contact` WHERE `user_id`='{$user['id']}' AND `type`='2' AND `friends`='1'"), 0);
    echo '<div class="menu"><img src="../images/anketa/status.png" alt="*"/> <a href="/status/statuslar.php?id=' . $user['id'] . '">Statuslar</a> ('.$bender_statuslari.')</div>';

	echo '' .
        '<div class="menu"><p><img src="../images/anketa/fotos.png" alt="*"/> ' . '<a href="album.php?act=list&amp;user=' . $user['id'] . '">' . $lng['photo_album'] . '</a>&#160;(' . $total_photo . ')</div>' .
        
		
	
        //gift sovga boshlanishi
		'<div class="menu"><p><img src="../images/anketa/sovgalar.png" alt="*"/> <a href="/gifts/index.php?act=showall&amp;user=' . $user['id'] . '">' . $lng_gifts['showall'] . '</a>&#160;(' . $total_gifts . ')</div>' .
        '<div class="menu"><p><img src="../images/anketa/sovgalar.png" alt="*"/> <a href="/gifts/index.php?user=' . $user['id'] . '">' . $lng_gifts['send'] . '</a></div>' .
		//gift sovga tugashi

		'<div class="menu"><p><img src="../images/anketa/dust.png" alt="*"/> <a href="profile.php?act=friends&amp;user=' . $user['id'] . '">' . $lng_profile['friends'] . '</a>&#160;(' . $total_friends . ')</div>' .
		#'<div class="menu"><p>&#160;&#187;&#160;' . '<a href="anketa.php"> Profilni yopish</a></div>';
		
		'';
require 'guests.php';
    if ($user['id'] != $user_id) {
        echo '';
		


        // Контакты
        if (!functions::is_ignor($user['id']) && functions::is_contact($user['id']) != 2) {
            if (!functions::is_friend($user['id'])) {
                $fr_in = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_contact` WHERE `type`='2' AND `from_id`='$user_id' AND `user_id`='{$user['id']}'"), 0);
                $fr_out = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_contact` WHERE `type`='2' AND `user_id`='$user_id' AND `from_id`='{$user['id']}'"), 0);
       			if ($fr_in == 1) {
                    $friend = '<a class="underline" href="profile.php?act=friends&amp;do=ok&amp;id=' . $user['id'] . '">' . $lng_profile['confirm_friendship'] . '</a> | <a class="underline" href="profile.php?act=friends&amp;do=no&amp;id=' . $user['id'] . '">' . $lng_profile['decline_friendship'] . '</a>';
                } else if ($fr_out == 1) {
                    $friend = '<a class="underline" href="profile.php?act=friends&amp;do=cancel&amp;id=' . $user['id'] . '">' . $lng_profile['canceled_demand_friend'] . '</a>';
                } else {
                    $friend = '<a href="profile.php?act=friends&amp;do=add&amp;id=' . $user['id'] . '">' . $lng_profile['in_friend'] . '</a>';
                }
                } else {
                  $friend = '<a href="profile.php?act=friends&amp;do=delete&amp;id=' . $user['id'] . '">' . $lng_profile['remov_friend'] . '</a>';
                }
                echo '<div class="menu"><p>&#160;&#187;&#160;' . $friend . '</div>';
                }

        if (functions::is_contact($user['id']) != 2) {
            if (!functions::is_contact($user['id'])) {
                echo '<div class="menu"><p>&#160;&#187;&#160;<a href="../mail/index.php?id=' . $user['id'] . '">' . $lng_profile['add_contacts'] . '</a></div>';
            } else {
				
                echo '<div class="menu"><p>&#160;&#187;&#160;<a href="../mail/index.php?act=deluser&amp;id=' . $user['id'] . '">' . $lng_profile['delete_contacts'] . '</a></div>';
            }
        }

        if (functions::is_contact($user['id']) != 2) {
            echo '<div class="menu"><p>&#160;&#187;&#160;<a href="../mail/index.php?act=ignor&amp;id=' . $user['id'] . '&amp;add">' . $lng_profile['add_ignor'] . '</a></div>';
        } else {
            echo '<div class="menu"><p>&#160;&#187;&#160;<a href="../mail/index.php?act=ignor&amp;id=' . $user['id'] . '&amp;del">' . $lng_profile['delete_ignor'] . '</a>';
        }
        echo '';
		
			
        if (!functions::is_ignor($user['id']) && functions::is_contact($user['id']) != 2 && empty($ban['1']) && empty($ban['3'])) {
			 
			 echo '<div class="menu"><center><div class="post_item" style="padding-top: 5px; padding-bottom: 5px; "><a href="../mail/index.php?act=write&amp;id=' . $user['id'] . '" class="ssilka" style="display: block; max-width: 200px;">' . $lng['write'] . '</a></div></center></div>';
			

            
        //echo '<div class="menu"><p><form action="../mail/index.php?act=write&amp;id=' . $user['id'] . '" method="post"><input type="submit" value="' . $lng['write'] . '" style="margin-left: 18px"/></form></p>';
		}
		
        echo '</div>';
		
    }

	echo '<div class="rmenu"><table class="whp">Foydalanuvchilarni izlash<tr><td class="pr5"><form action="search.php" method="post">
<input class="finp whp fss" type="text" size="100" name="search" placeholder="foydalanuvchi ismini kiriting"/>
<td class="srcbc pls"><input type="submit" value="Izlash" name="submit" /></td></td></tr></table></form></div>';

    #echo '<div class="phdr"><a href="index.php">' . $lng['users'] . '</a></div>';
	} 

/// Yopiq anketa
$friends = mysql_result(mysql_query("SELECT COUNT(*) FROM `friend` WHERE (`user` = '" . $user['id'] . "' AND `friend` = '$user_id') OR (`user` = '$user_id' AND `friend` = '" . $user['id'] . "')"), 0);

if ($user['id'] !=$user_id && mysql_result(mysql_query("SELECT COUNT(*) FROM `friend_notice` WHERE (`user` = '" . $user['id'] . "' AND `to` = '$user_id') OR (`user` = '$user_id' AND `to` = '" . $user['id'] . "')"), 0) == 0 && $friends == 0){
if($user['eas']==1){
//echo '<div class="menu" align="center"><font color="red">Kechirasiz ushbu anketa faqat do`stlari uchun ochiq!</font><br/>&#187; <a href="friend.php?act=add&amp;user=' . $user['id'] . '"> Do\'stlarga  qo\'shish</a></div>';
require_once('../incfiles/end.php');
exit;
}}
///////////////////////////////////
//(дe)aктивaция бoтa
if($rights==9)
{
   echo '<div class="menu"><img src="../images/settings.png" width="16" height="16"/>&#160;<a href="bot.php?id=' . $user['id'] . '">'.($user['bot']==1 ? 'OFF onlayn bot' : 'ON onlayn bot').'</a></div>';
}
/////////

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