<?PHP
$user_id = htmlspecialchars($_GET['name']);
$usname = $_SESSION["user"];
$_OPTIMIZATION["title"] = "Стена пользователя &laquo;".$user_id."&raquo;";
$db->Query("SELECT * FROM db_users_a, db_users_b WHERE db_users_a.user = db_users_b.user AND db_users_a.user = '$user_id'");
$prof_data = $db->FetchArray();


$db->Query("SELECT COUNT(*) FROM db_users_a WHERE referer_id = '".$prof_data["id"]."'");
$refs = $db->FetchRow(); // Считаем рефералов 1 уровня
$db->Query("SELECT COUNT(*) FROM db_users_a WHERE referer_id2 = '".$prof_data["id"]."'");
$refs2 = $db->FetchRow(); // Считаем рефералов 2 уровня
$db->Query("SELECT COUNT(*) FROM db_users_a WHERE referer_id3 = '".$prof_data["id"]."'");
$refs3 = $db->FetchRow(); // Считаем рефералов 3 уровня


# ========= вывод всего заработано на рефералах ========= #
        $db->Query("SELECT doxod2 FROM db_users_a WHERE referer_id2 = '".$prof_data["id"]."'");
        $doxod_refs2 = $db->FetchArray();
        $doxod_refs2['doxod2'];

        $db->Query("SELECT doxod2,doxod3 FROM db_users_a WHERE referer_id3 = '".$prof_data["id"]."'");
        $doxod_refs3 = $db->FetchArray();
        $doxod_refs3['doxod3'];

        $zarab_na_refax = $prof_data["from_referals"] + $doxod_refs2['doxod2'] + $doxod_refs3['doxod3'];

$db->Query("SELECT * FROM db_users_b WHERE id = '".$prof_data["id"]."' LIMIT 1");
$user_data = $db->FetchArray();

$db->Query("SELECT * FROM db_config WHERE id = '1' LIMIT 1");
$sonfig_site = $db->FetchArray();



$A=$func->SumCalc($sonfig_site["a_in_h"], $user_data["a_t"], $user_data["last_sbor"]);
$B=$func->SumCalc($sonfig_site["b_in_h"], $user_data["b_t"], $user_data["last_sbor"]);
$C=$func->SumCalc($sonfig_site["c_in_h"], $user_data["c_t"], $user_data["last_sbor"]);
$D=$func->SumCalc($sonfig_site["d_in_h"], $user_data["d_t"], $user_data["last_sbor"]);
$E=$func->SumCalc($sonfig_site["e_in_h"], $user_data["e_t"], $user_data["last_sbor"]);
$F=$func->SumCalc($sonfig_site["f_in_h"], $user_data["f_t"], $user_data["last_sbor"]);
$G=$A+$B+$C+$D+$E+$F;

$kyr1 = $user_data["a_t"]*$sonfig_site["a_in_h"];
$kyr2 = $user_data["b_t"]*$sonfig_site["b_in_h"];
$kyr3 = $user_data["c_t"]*$sonfig_site["c_in_h"];
$kyr4 = $user_data["d_t"]*$sonfig_site["d_in_h"];
$kyr5 = $user_data["e_t"]*$sonfig_site["e_in_h"];
$kyr6 = $user_data["f_t"]*$sonfig_site["f_in_h"];

$kyrcall = $kyr1+$kyr2+$kyr3+$kyr4+$kyr5+$kyr6;

$start_end_email = preg_match( "/^([a-z0-9\-\.\_]+)(@[a-z0-9]+(?:\.?[a-z0-9]+)?\.[a-z]{2,5})/is", $prof_data["email"], $outemail );
$sec_email_user = substr( $outemail[1], 0, 1 ) . '****' . substr( $outemail[1], -1) . $outemail[2];

?>
<div class="page-content-wrapper ">

    <div class="container">

        <div class="row">
            <div class="col-sm-6 col-lg-3">
                <div class="panel text-center">
                    <div class="panel-heading">
                        <h4 class="panel-title text-muted font-light profilemsz">Скорость заработка</h4>
                    </div>
                    <div class="panel-body p-t-10">
                        <h2 class="m-t-0 m-b-15 profilemst"><i class="mdi mdi-speedometer text-danger m-r-10"></i><b><?php echo sprintf("%.4f",$kyrcall/$sonfig_site["items_per_coin"]);?>Р / час</b></h2>
                        <!--<p class="text-muted m-b-0 m-t-20"><mark class="profilemsd">Больше чем у <b>88%</b> пользователей</mark></p>-->
                    </div>
                </div>
            </div>
            <div class="col-sm-6 col-lg-3">
                <div class="panel text-center">
                    <div class="panel-heading">
                        <h4 class="panel-title text-muted font-light profilemsz">Количество рефералов</h4>
                    </div>
                    <div class="panel-body p-t-10">
                        <h2 class="m-t-0 m-b-15 profilemst"><i class="mdi mdi-account-multiple text-primary m-r-10"></i><b><?=$refs; ?> чел.</b></h2>
                        <!--<p class="text-muted m-b-0 m-t-20"><mark class="profilemsd">Больше чем у <b>99%</b> пользователей</mark></p>-->
                    </div>
                </div>
            </div>
            <div class="col-sm-6 col-lg-3">
                <div class="panel text-center">
                    <div class="panel-heading">
                        <h4 class="panel-title text-muted font-light profilemsz">Выплачено заработка</h4>
                    </div>
                    <div class="panel-body p-t-10">
                        <h2 class="m-t-0 m-b-15 profilemst"><i class="mdi mdi-cash-multiple text-primary m-r-10"></i><b><?=$prof_data["payment_sum"]; ?> <i class="fa fa-ruble" style="font-size:22px;"></i></b></h2>
                        <!--<p class="text-muted m-b-0 m-t-20"><mark class="profilemsd">Больше чем у <b>99%</b> пользователей</mark></p>-->
                    </div>
                </div>
            </div>
            <div class="col-sm-6 col-lg-3">
                <div class="panel text-center">
                    <div class="panel-heading">
                        <h4 class="panel-title text-muted font-light profilemsz">Кликов в сёрфинге</h4>
                    </div>
                    <div class="panel-body p-t-10">
                        <h2 class="m-t-0 m-b-15 profilemst"><i class="mdi mdi-mouse text-danger m-r-10"></i><b><?=$prof_data["s_view"]; ?></b></h2>
                        <!--<p class="text-muted m-b-0 m-t-20"><mark class="profilemsd">Больше чем у <b>81%</b> пользователей</mark></p>-->
                    </div>
                </div>
            </div>
        </div>
        <!-- end row -->

        <div class="row">
            <div class="col-sm-6 col-lg-3">
                <div class="panel panel-default">
  <div class="panel-heading"><h3 class="panel-title">Данные аккаунта</h3></div>
                    <div class="panel-body">
                        <h5 class="profileinfoh5">Имя: <span><?=$prof_data["real_name"]; ?></span></h5>
  <h5 class="profileinfoh5">Логин: <span><?=$prof_data["user"]; ?></span></h5>
  <h5 class="profileinfoh5">E-mail: <span class="profileinfospan"><?=$sec_email_user?></span></h5>
  <h5 class="profileinfoh5">ID в системе: <span>#<?=$prof_data["id"]; ?></span></h5>
  <h5 class="profileinfoh5">Пригласил: <span><?if($prof_data["referer"]=='') echo 'сам пришел'; else echo '<a href="/wall/'.$prof_data["referer"].'">'.$prof_data["referer"].'</a>'; ?><span></h5>
  <h5 class="profileinfoh5">Регистрация: <span><?=date("d.m.Y в H:i",$prof_data["date_reg"]); ?></span></h5>
  <h5 class="profileinfoh5">Последний вход: <span><?=date("d.m.Y в H:i",$prof_data["date_login"]); ?></span></h5>
</div>
                </div>
            </div>
            <div class="col-sm-6 col-lg-3">
                <div class="panel panel-default">
  <div class="panel-heading"><h3 class="panel-title">Статистика аккаунта</h3></div>
                    <div class="panel-body">
                        <h5 class="profileinfoh5">Сумма пополнений: <span><?=$prof_data["insert_sum"]; ?> <i class="fa fa-ruble" style="font-size:14px;"></i></span></h5>
  <h5 class="profileinfoh5">Сумма выплат: <span><?=$prof_data["payment_sum"]; ?> <i class="fa fa-ruble" style="font-size:14px;"></i></span></h5>
  <h5 class="profileinfoh5">Доход с рефералов: <span><?=sprintf("%.2f",$zarab_na_refax); ?> <i class="fa fa-ruble" style="font-size:14px;"></i></span></h5>
  <h5 class="profileinfoh5">Кол-во рефералов: <span><?=$refs; ?> чел.</span></h5>
  <h5 class="profileinfoh5">Купил танков: <span><?=$prof_data["a_t"]+$prof_data["b_t"]+$prof_data["c_t"]+$prof_data["d_t"]+$prof_data["e_t"]+$prof_data["f_t"]; ?> ед.</span></h5>
  <h5 class="profileinfoh5">Дней в игре: <span><?=intval(((time() - $prof_data["date_reg"]) / 86400 ) +1); ?></span></h5>
                        <button type="button" class="btn waves-effect btn-default btn-block" onclick="location.href='/wall/<?=$usname?>';"> <i class="mdi mdi-account-box"></i> Стена пользователя</button>
</div>
                </div>
            </div>
            <div class="col-sm-12 col-xs-12 col-lg-6">
                <div class="panel panel-default">
  <div class="panel-heading"><h3 class="panel-title">График изменения скорости заработка</h3></div>
                    <div class="panel-body">
                                                  <?

        $db->Query( "SELECT statistic FROM db_users_a WHERE id = '" . $prof_data["id"] . "' LIMIT 1" );
    while($serfStat = $db->FetchArray()) {
    $serfStatRow = $serfStat ;
    $array = unserialize( $serfStatRow['statistic'] );
    if ( empty( $array ) ) {
        $d1 = 0; $d2 = 0; $d3 = 0; $d4 = 0; $d5 = 0; $d6 = 0; $d7 = 0;
    } else {
        if ( empty( $array[date( 'dmY' )] ) ) $d1 = 0; else $d1 = $array[date( 'dmY' )];
        if ( empty( $array[date( 'dmY', time() - 86400 )] ) ) $d2 = 0; else $d2 = $array[date( 'dmY', time() - 86400 )];
        if ( empty( $array[date( 'dmY', time() - 86400 * 2 )] ) ) $d3 = 0; else $d3 = $array[date( 'dmY', time() - 86400 * 2 )];
        if ( empty( $array[date( 'dmY', time() - 86400 * 3 )] ) ) $d4 = 0; else $d4 = $array[date( 'dmY', time() - 86400 * 3 )];
        if ( empty( $array[date( 'dmY', time() - 86400 * 4 )] ) ) $d5 = 0; else $d5 = $array[date( 'dmY', time() - 86400 * 4 )];
        if ( empty( $array[date( 'dmY', time() - 86400 * 5 )] ) ) $d6 = 0; else $d6 = $array[date( 'dmY', time() - 86400 * 5 )];
        if ( empty( $array[date( 'dmY', time() - 86400 * 6 )] ) ) $d7 = 0; else $d7 = $array[date( 'dmY', time() - 86400 * 6 )];
    }

    $month = array( 'янв', 'фев', 'мар', 'апр', 'май', 'июн', 'июл', 'авг', 'сен', 'окт', 'ноя', 'дек' );

    switch ( date( 'd' ) ) {
        case 1:
            $thismonth7 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth6 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth5 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth4 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth3 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth2 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth1 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            break;
        case 2:
            $thismonth7 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth6 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth5 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth4 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth3 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth2 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth1 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            break;
        case 3:
            $thismonth7 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth6 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth5 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth4 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth3 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth2 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth1 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            break;
        case 4:
            $thismonth7 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth6 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth5 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth4 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth3 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth2 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth1 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            break;
        case 5:
            $thismonth7 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth6 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth5 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth4 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth3 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth2 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth1 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            break;
        case 6:
            $thismonth7 = ' ' . $month[( int ) date( 'm', time() ) - 2] . ' ' . date( 'Y', time() );
            $thismonth6 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth5 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth4 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth3 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth2 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth1 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            break;
        default:
            $thismonth7 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth6 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth5 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth4 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth3 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth2 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            $thismonth1 = ' ' . $month[( int ) date( 'm', time() ) - 1] . ' ' . date( 'Y', time() );
            break;
    }
        ?>

     <script type="text/javascript">
        $(function () {
        eval($('#code').text());
        prettyPrint();
       });

    </script>
    <div id="graph" style="height: 230px; margin-top:-20px;margin-bottom:-15px;" class="profilecharth"></div>
    <div style="display:none;" id="code">
Morris.Donut({
  element: 'graph',
  data: [
    {value: <?=$prof_data["speed"]; ?>, label: 'Скорость руб.', formatted: '<?=$prof_data["speed"]; ?>' },
    {value: <?=$prof_data["payment_sum"]; ?>, label: 'Выплачено руб.', formatted: '<?=$prof_data["payment_sum"]; ?>' },
    {value: <?=$prof_data["money_serf"]; ?>, label: 'Серфинг.', formatted: '<?=$prof_data["money_serf"]; ?>' }
  ],
  formatter: function (x, data) { return data.formatted; }
});
</div>
   <?
 }
?>



                    </div>
                </div>
            </div>
        </div>
        <!-- end row -->

        <div class="row">
            <div class="col-sm-12">
                <div class="panel panel-primary">
                    <div class="panel-body">
                        <h4 class="m-t-0">Список моих грузовиков</h4>
  <div class="row">
    <div class="col-lg-1 col-sm-2 col-xs-2 text-center">
          <img src="/img/shop/n1.png" class="profilecarimg"><h3>x<?=$prof_data["a_t"]; ?></h3></div>
    <div class="col-lg-1 col-sm-2 col-xs-2 text-center">
          <img src="/img/shop/n2.png" class="profilecarimg"><h3>x<?=$prof_data["b_t"]; ?></h3></div>
    <div class="col-lg-1 col-sm-2 col-xs-2 text-center">
          <img src="/img/shop/n3.png" class="profilecarimg"><h3>x<?=$prof_data["c_t"]; ?></h3></div>
    <div class="col-lg-1 col-sm-2 col-xs-2 text-center">
          <img src="/img/shop/n4.png" class="profilecarimg"><h3>x<?=$prof_data["d_t"]; ?></h3></div>
    <div class="col-lg-1 col-sm-2 col-xs-2 text-center">
          <img src="/img/shop/n5.png" class="profilecarimg"><h3>x<?=$prof_data["e_t"]; ?></h3></div>
    <div class="col-lg-1 col-sm-2 col-xs-2 text-center">
          <img src="/img/shop/n6.png" class="profilecarimg"><h3>x<?=$prof_data["f_t"]; ?></h3></div>
      </div>  </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- end row -->

    </div><!-- container -->


</div> <!-- Page content Wrapper -->
</div> <!-- content -->