<?

session_start();

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

define( 'ROOT_DIR', $_SERVER['DOCUMENT_ROOT'] );

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

if ( !isset( $_SESSION['iduser'] ) ) exit();

include_once ROOT_DIR . '/engine/config.php';
include_once ROOT_DIR . '/engine/function.php';

$id = ( int ) $_GET['id'];
$user_modal_info = mysql_fetch_array( mysql_query( "SELECT * FROM user WHERE id = '" . $id . "' " ) );
$ref_user_info_modal = mysql_fetch_array( mysql_query( "SELECT referals FROM user WHERE id = '" . $user_modal_info['id'] . "' LIMIT 1" ) );
$ref2_user_info_modal = mysql_fetch_array( mysql_query( "SELECT COUNT(id) as count FROM user WHERE referer2 = '" . $user_modal_info['id'] . "'" ) );
$user_info_modal_contests = mysql_fetch_array( mysql_query( "SELECT COUNT(id) as count FROM contests WHERE autor = '" . $user_modal_info['id'] . "' AND date_end > '" . time() . "'" ) );

if ( $_SERVER['HTTP_HOST'] == $user_modal_info['rsite'] ) {
    $user_modal_info['rsite'] = 'Странник';
}

?>
  <div class="modal fade bd-example-modal-lg" id="modalf">
	  <div class="modal-dialog " role="document">
		<div class="modal-content" style="width: 637px; margin-left: -54px;">
		  <div class="modal-header">
			<button type="button" class="close" data-dismiss="modal" aria-label="Close">
			  <span aria-hidden="true">&times;</span>
			</button>
			<h4 class="modal-title">Статистика пользователя - <?=$user_modal_info['name']?></h4>
		  </div>
		  
		  <div class="modal-body"><!--Содержимое модального окна начало-->
			<div class="user-info-avatar">
			  <div class="div_centralizator">
			    <img src="/temp/avatar/<?=$user_modal_info['avatar']?>" width="64" height="64" class="img-thumbnail user-info-modal-avatar" alt="" />
			  </div>
			</div>
			<div class="user-info-table">
			  <table class="table table-sm">
				  <tbody>
					<tr>
					  <td>Имя пользователя:</td>
					  <td><?=$user_modal_info['name']?></td>
					</tr>
					<tr>
					  <td>Статус пользователя:</td>
					  <td><?=status_user( $user_modal_info['reyting'], $user_modal_info['account'] )?></td>
					</tr>
					<tr>
					  <td>Дата регистрации:</td>
					  <td><?=date( 'd.m.Y', $user_modal_info['regdate'] )?></td>
					</tr>
					<tr>
					  <td>Авторефбек:</td>
					  <td><?=$user_modal_info['autoback']?>%</td>
					</tr>
					<tr>
					  <td>Рефералы 1-уровня:</td>
					  <td><?=$ref_user_info_modal['referals']?></td>
					</tr>
					<tr>
					  <td>Рефералы 2-уровня:</td>
					  <td><?=$ref2_user_info_modal['count']?></td>
					</tr>
					<tr>
					  <td>Конкурсы рефералам:</td>
					  <td><?=$user_info_modal_contests['count']?></td>
					</tr>
					<tr>
					  <td>Откуда пришел:</td>
					  <td><?=$user_modal_info['rsite']?></td>
					</tr>
				  </tbody>
				</table>
			</div>
			<div class="user-info-stat">
			  <?
				include_once ROOT_DIR . '/engine/classes/graphics.class.php';
				echo visit_statistic_wall( $user_modal_info['id'], 500, 270 );
			  ?>
			</div>
		  </div><!--Содержимое модального окна конец-->
		  
		  <div class="modal-footer">
			<button type="button" class="btn btn-secondary" data-dismiss="modal">Закрыть</button>
		  </div>
		</div>
	  </div>
  </div>
	
  <script type="text/javascript">
	$(document).ready(function(){
		var options = {
			show : true
		}
		$('#modalf').modal(options);
	});

	function send_msg() {
		$.post('ajax.php?func=newmsg',{
			id : <?=$id?>,
			type: '<?=$type?>',
			text: $('#message-text').val()
			
		}, function(data){
			if (data == 1){
				$(".form-group").fadeOut(0);
				$("#send_walls_gift").fadeOut(0);
				$("#success_text").fadeIn(300);
			} else
			if (data == 2){
				$('.error_modal_ultimate').fadeIn().html("Сообщение не может быть пустым!");
				setTimeout(function() {
					$('.error_modal_ultimate').fadeOut().html('&nbsp;');
				}, 4000);
			} else
			if (data == 3){
				$('.error_modal_ultimate').fadeIn().html("Отправлять самому себе сообщения??? <i class='fa fa-meh-o' aria-hidden='true'></i> Зачем? ");
				setTimeout(function() {
					$('.error_modal_ultimate').fadeOut().html('&nbsp;');
				}, 4000);
			} else {
				$('.error_modal_ultimate').fadeIn().html(data);
				setTimeout(function() {
					$('.error_modal_ultimate').fadeOut().html('&nbsp;');
				}, 4000);
			}
		});
		return false;
	}

  </script>