<?php
include 'nigration.php';
include_once 'marat_security.php';
$host = 'localhost'; //хост базы
$db = 'cu47948_ak';
$user = 'cu47948_ak';
$pass = 'cu47948_ak';
$charset = 'UTF8';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC );

$pdo = new PDO($dsn, $user, $pass, $opt);
$pdo->exec("set names utf8");


$config_site = $pdo->Query("SELECT * from php_engine WHERE id = 1")->fetch(PDO::FETCH_BOTH);
$config_pay = $pdo->Query("SELECT * from php_config WHERE id = 1")->fetch(PDO::FETCH_BOTH);
$config_per_us = $pdo->Query("SELECT * from php_percent WHERE id = 1")->fetch(PDO::FETCH_BOTH);

$bd_host = "localhost"; // хост
$bd_user = "cu47948_ak"; // логин
$bd_password = "cu47948_ak";  // пароль
$bd_base = "cu47948_ak"; // БД

$con = mysql_connect( $bd_host, $bd_user, $bd_password ) or die( 'База данных перегружена' );
mysql_select_db( $bd_base, $con );
mysql_query( "set names utf8" );

if ( isset( $_SESSION['id'] ) ) {
    $config_us = $pdo->Query("SELECT * from php_user WHERE id = '" . $_SESSION['id'] . "'")->fetch(PDO::FETCH_BOTH);
    $config_user = $pdo->Query("SELECT * from php_user WHERE id = '" . $_SESSION['id'] . "'")->fetch(PDO::FETCH_BOTH); 
    /*---Награды и заслуги---*/
    //привлечение рефералов
    if ( $config_us['reyt'] >= 0 and $config_us['reyt'] < 20 ) {
        $pdo->Query( "UPDATE php_user SET percent = 0.2, part_pecent = '" . $config_per_us['percent1'] ."' WHERE id = '" . $_SESSION['id'] . "' LIMIT 1" );
    }
    if ( $config_us['reyt'] >= 20 and $config_us['reyt'] < 30 ) {
        $pdo->Query( "UPDATE php_user SET percent = 0.18, part_pecent = '" . $config_per_us['percent2'] ."' WHERE id = '" . $_SESSION['id'] . "' LIMIT 1" );
    }
    if ( $config_us['reyt'] >= 30 and $config_us['reyt'] < 50 ) {
        $pdo->Query( "UPDATE php_user SET percent = 0.16, part_pecent = '" . $config_per_us['percent3'] ."' WHERE id = '" . $_SESSION['id'] . "' LIMIT 1" );
    }
    if ( $config_us['reyt'] >= 50 and $config_us['reyt'] < 100 ) {
        $pdo->Query( "UPDATE php_user SET percent = 0.14, part_pecent = '" . $config_per_us['percent4'] ."' WHERE id = '" . $_SESSION['id'] . "' LIMIT 1" );
    }
    if ( $config_us['reyt'] >= 100 ) {
        $pdo->Query( "UPDATE php_user SET percent = 0.12, part_pecent = '" . $config_per_us['percent5'] ."' WHERE id = '" . $_SESSION['id'] . "' LIMIT 1" );
    }

   $sql_mess = mysql_fetch_array( mysql_query( "SELECT COUNT(id) as count FROM php_messages WHERE to_id = '" . $_SESSION['id'] . "' and m_state = 'inbox' and m_type = 0" ) );

   if ( $sql_mess['count'] > 0 ) {
    $count_mess = '<div class="count_mess">' . $sql_mess['count'] . '</div>';
   } else {
    $count_mess = '';
   }
}
?>