<?php
session_start();

error_reporting( 1 );

header( 'Content-type: text/html; charset=windows-1251' );

if (!(isset($_SESSION["username"]) && isset($_SESSION["password"]))) {
	exit();
}

if ( $_SERVER['HTTP_X_REQUESTED_WITH'] != 'XMLHttpRequest' ) {
    exit();
}

include 'sfb.php';

$getinfo = mysql_fetch_array( mysql_query( "SELECT pemail, reyting, id, avatar, username, joindate, lastlogdate, country, ban, refsite, finestatus FROM tb_users WHERE id = '" . intval($_POST['usid']) . "'" ) );

$ref1 = mysql_fetch_array( mysql_query( "SELECT count(*) as count FROM tb_users WHERE referer = '" . $getinfo['id'] . "'" ) );
//$ref2 = mysql_fetch_array( mysql_query( "SELECT count(*) as count FROM tb_users WHERE referer2 = '" . $getinfo['id'] . "'" ) );
if ($getinfo['pemail'] == '') {
    $rrey = 'Прохожий';
    $usstatus = '';
    $reycolor = 'color: #8D950B; text-shadow: 0 0 0.2em #8D950B;';
} else
if ($getinfo['reyting'] >= 1 and $getinfo['reyting'] < 10 and $getinfo['pemail'] != '') {
    $rrey = 'Стажер';
    $usstatus = '';
    $reycolor = 'color: #8D950B; text-shadow: 0 0 0.2em #8D950B;';
} else
if ($getinfo['reyting'] >= 10 and $getinfo['reyting'] < 100 and $getinfo['pemail'] != '') {
    $rrey = 'Рабочий';
    $usstatus = '';
    $reycolor = 'color: #8D950B; text-shadow: 0 0 0.2em #8D950B;';
} else
if ($getinfo['reyting'] >= 100 and $getinfo['reyting'] < 250 and $getinfo['pemail'] != '') {
    $rrey = 'Бригадир';
    $usstatus = '';
    $reycolor = 'color: #8D950B; text-shadow: 0 0 0.2em #8D950B;';
} else
if ($getinfo['reyting'] >= 250 and $getinfo['reyting'] < 600 and $getinfo['pemail'] != '') {
    $rrey = 'Мастер';
    $usstatus = '<img src="theme/img/status/master.png" width="26" height="40" class="usstatusr" />';
    $reycolor = 'color: #8D950B; text-shadow: 0 0 0.2em #8D950B;';
} else
if ($getinfo['reyting'] >= 600 and $getinfo['reyting'] < 1000 and $getinfo['pemail'] != '') {
    $rrey = 'Бизнесмен';
    $usstatus = '<img src="theme/img/status/s_master.png" width="26" height="40" class="usstatusr" />';
    $reycolor = 'color: #800000; text-shadow: 0 0 0.2em #800000;';
} else
if ($getinfo['reyting'] >= 1000 and $getinfo['pemail'] != '') {
    $rrey = 'Олигарх';
    $usstatus = '<img src="theme/img/status/oligarh.png" width="26" height="40" class="usstatusr" />';
    $reycolor = 'color: #1c62b9; text-shadow: 0 0 0.2em #1c62b9;';
} else {
    $rrey = 'Никто';
    $usstatus = '';
    $reycolor = 'color: #8D950B';
}
if ($getinfo['ban'] == 1) { $rrey = '<font color="#800000">Заблокирован</font>';}

if ($getinfo['refsite'] != '') {
    $hr = '<a href="http://' . htmlspecialchars($getinfo['refsite']) . '" target="_blank" class="link">' . substr($getinfo['refsite'], 0, 20) . '</a>';
} else {
    $hr = '<a href="http://' . htmlspecialchars($_SERVER['HTTP_HOST']) . '" target="_blank" class="link">' . substr($_SERVER['HTTP_HOST'], 0, 20) . '</a>';
}
?>
<style type="text/css">
.refinfo td {
    padding: 5px;
}
.refinfo {
    margin-bottom: 10px;
    border-bottom: 1px dotted #cccccc;
    color: #212121;
}
.rey {
    background: url(theme/images/img_reyting.png) 0 0 no-repeat;
    width: 60px;
    height: 55px;
    text-align: center;
}
.rey span {
    position: relative;
    top: 19px;
    text-shadow: 0 0 1px #ffffff;
    font-weight: bold;
}
.usstatusr {
    position: absolute;
    bottom: 3px;
    right: 5px;
}
</style>
<script type="text/javascript">$('.rey').tipTip();</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="refinfo">
    <tr>
        <td width="80" align="center" valign="top"><div style="position: relative;"><img src="avp/<?=$getinfo['avatar']?>" width="60" height="60" class="avatar" /><?=$usstatus?></div></td>
        <td width="100">ID<br />Ник<br />Откуда<br />Приглашен с<br />Регистрация<br />Последний визит<br />Статус<br />Рефералов</td>
        <td width="100"><?=$getinfo['id']?><br /><font color="#800000"><?=$getinfo['username']?></font><br /><?=$getinfo['country']?><br /><?=$hr?><br /><?=date('d.m.Y', $getinfo['joindate'])?><br /><? if($getinfo['lastlogdate'] == ''){echo '-';}else{echo date('d.m.Y', $getinfo['lastlogdate']);}?><br /><font color="#EC8A09"><? if($getinfo['finestatus'] == 0) { echo $rrey; } else { echo 'Штрафник'; } ?></font><br /><?=$ref1['count']?></td>
        <td align="center" valign="top"><div class="rey" style="<?=$reycolor?>" title="Рейтинг: <?=number_format($getinfo['reyting'], 1, '.', '')?>"><span><?=floor($getinfo['reyting'])?></span></div></td>
    </tr>
</table>
<center style="color: #212121;">
<div align="center" style="color: #286286; font-weight: bold; margin-bottom: 5px;">Статистика пользователя</div>
<?
$user = $getinfo['id'];
$row0 = mysql_fetch_array(mysql_query("select count(id) as kolvo from tb_statistic where typ=0 and username='$user'"));
$row1 = mysql_fetch_array(mysql_query("select count(id) as kolvo from tb_statistic where typ=1 and username='$user'"));
$row2 = mysql_fetch_array(mysql_query("select count(id) as kolvo from tb_statistic where typ=2 and username='$user'"));
$tmpstr = date("w");
    
if (!$row0["kolvo"]) mysql_query("INSERT INTO tb_statistic (username, typ, total, date) VALUES('$user','0','0','$tmpstr')") or die(mysql_error());
if (!$row1["kolvo"]) mysql_query("INSERT INTO tb_statistic (username, typ, total, date) VALUES('$user','1','0','$tmpstr')") or die(mysql_error());
if (!$row2["kolvo"]) mysql_query("INSERT INTO tb_statistic (username, typ, total, date) VALUES('$user','2','0','$tmpstr')") or die(mysql_error());
$seoedit = 1;
require 'mod_wrc/stat_diogram.php';
initstat($user,1);
?>
</center>