<?
### Версия ПО (ДМ) 1.0.0.0 ( (c)2018 MISOFT Продукт защищен регистрацией патента и авторских прав! www.misoft.studio )
######################################################################################################################

if ( $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) {
  define( 'ROOT_DIR', $_SERVER['DOCUMENT_ROOT'] );
  session_start();
  header( 'Content-type: text/html; charset=windows-1251' );
  include_once ROOT_DIR . '/engine/config.php';
  include_once ROOT_DIR . '/engine/function.php';
} else {
   if ( !defined( 'MISOFT' ) ) { exit(); }
}

$payments = mysql_query( "SELECT * FROM pay_history ORDER BY date DESC LIMIT 50" );

$sum_kol_payments = mysql_fetch_array( mysql_query( "SELECT SUM(money) as sum FROM pay_history WHERE date >= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:00' ) - 86400 ) . "' and date <= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:00' ) + 86400 ) . "'" ) );

$view1 = mysql_fetch_array( mysql_query( "SELECT SUM(money) as sum FROM pay_history WHERE date >= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:01' ) ) . "' and date <= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:00' ) + 86400 ) . "'" ) );

$view2 = mysql_fetch_array( mysql_query( "SELECT SUM(money) as sum FROM pay_history WHERE date >= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:01' ) - 86400 ) . "' and date <= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:00' ) ) . "'" ) );

$view3 = mysql_fetch_array( mysql_query( "SELECT SUM(money) as sum FROM pay_history WHERE date >= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:01' ) - 86400 * 2 ) . "' and date <= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:00' ) - 86400 ) . "'" ) );

$view4 = mysql_fetch_array( mysql_query( "SELECT SUM(money) as sum FROM pay_history WHERE date >= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:01' ) - 86400 * 3 ) . "' and date <= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:00' ) - 86400 * 2 ) . "'" ) );

$view5 = mysql_fetch_array( mysql_query( "SELECT SUM(money) as sum FROM pay_history WHERE date >= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:01' ) - 86400 * 4 ) . "' and date <= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:00' ) - 86400 * 3 ) . "'" ) );

$view6 = mysql_fetch_array( mysql_query( "SELECT SUM(money) as sum FROM pay_history WHERE date >= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:01' ) - 86400 * 5 ) . "' and date <= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:00' ) - 86400 * 4 ) . "'" ) );

$view7 = mysql_fetch_array( mysql_query( "SELECT SUM(money) as sum FROM pay_history WHERE date >= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:01' ) - 86400 * 6 ) . "' and date <= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:00' ) - 86400 * 5 ) . "'" ) );

if ( empty( $view1['sum'] ) ) $view1['sum'] = 0;
if ( empty( $view2['sum'] ) ) $view2['sum'] = 0;
if ( empty( $view3['sum'] ) ) $view3['sum'] = 0;
if ( empty( $view4['sum'] ) ) $view4['sum'] = 0;
if ( empty( $view5['sum'] ) ) $view5['sum'] = 0;
if ( empty( $view6['sum'] ) ) $view6['sum'] = 0;
if ( empty( $view7['sum'] ) ) $view7['sum'] = 0;

if ( $sum_kol_payments['sum'] == '' ) {
  $sum_kol_payments['sum'] = 0;
}

$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 () {
    $('#graph-area').highcharts({
        chart: {
        type: 'areaspline',
        backgroundColor:'rgba(255, 255, 255, 0)'
        },
        title: {
            text: ''
        },
		exporting: {
			buttons: {
				contextButton: {
					enabled: false
				}
			}
		},
        subtitle: {
            text: ''
        },
        xAxis: {
            categories: [
                '<?=( int ) date( 'd', time() - 86400 * 6 ) . $thismonth7?>',
                '<?=( int ) date( 'd', time() - 86400 * 5 ) . $thismonth6?>',
                '<?=( int ) date( 'd', time() - 86400 * 4 ) . $thismonth5?>',
                '<?=( int ) date( 'd', time() - 86400 * 3 ) . $thismonth4?>',
                '<?=( int ) date( 'd', time() - 86400 * 2 ) . $thismonth3?>',
                '<?=( int ) date( 'd', time() - 86400 ) . $thismonth2?>',
                '<?=( int ) date( 'd', time() ) . $thismonth1?>'
            ]
        },
        yAxis: {
            min: 0,
            title: {
                text: ''
            },
            stackLabels: {
                enabled: true,
                style: {
                    fontWeight: 'bold',
                    color: '#31708f'
                }
            }
        },
        plotOptions: {
            column: {
                stacking: 'normal',                
            }
        },
		credits: {
			enabled: false
		},
        legend: {
            enabled: false
        },
        series: [{
            name: 'Выплачено',
            data: [<?=$view7['sum']?>, <?=$view6['sum']?>, <?=$view5['sum']?>, <?=$view4['sum']?>, <?=$view3['sum']?>, <?=$view2['sum']?>, <?=$view1['sum']?>]
        }]
    });
  });
</script>
<div class="content_bar content_bar_fix_chain">
  <article class="postBox">
	<div class="h2-title-header"><h2><a>Статистика выплат</a></h2></div>
	<div class="image_payments_24h_p"></div>
	<div class="textPreview" style="">
	  <p class="earnings_text" style="color: #545454;">
		Мы платим реальные деньги, и работаем прозрачно! Ниже вы можете ознакомится с статистикой выплат, которая отображает последние 50 выплат с текущего момента, а также график за <br/>последние 7 суток, с возрастающей кривой по суме и на каждый день. <br/>Тут может быть запись о вашей выплате, так чего же вы ждете? Пора <a href="/serfing" class="a_box">зарабатывать</a>! 
	  </p>
	</div>


    <div class="div_centralizator" style="width: 80%; height: 270px;  background: #FFFFFF; margin: 15px auto 15px auto; padding: 10px 0 0 0; border-bottom: 1px solid #e3e6e9;" id="graph-area"></div><br/>
    
	<div class="alert alert-info div_centralizator" role="alert">
	  <i class="fa fa-money" aria-hidden="true"></i> Всего выплачено за 24 часа: <strong><?=$sum_kol_payments['sum']?> <?=$config['valutaname']?></strong>
	</div>
    
	<div class="text_title " ><i class="fa fa-arrow-up" aria-hidden="true"></i> Последние 50 выплат</div>
	<table class="standartTable">
      <thead>
        <th style="text-align: center;">№ счета</th>
        <th>Пользователь</th>
        <th style="text-align: center;">Дата и время</th>
        <th style="text-align: center;">Сумма</th>
        <th style="text-align: center;">Метод оплаты</th>
      </thead>
      <?
      while ( $payments_row = mysql_fetch_array( $payments ) ) {
        if ( $payments_row['type'] == 1 ) {
            $pay_wmid = substr( $payments_row['purse'], 0, 9 ) . '<span style="color:#4769a3">XXX<span>';
            $pay_metod = '<span style="color:#0084d1">webmoney<span>';
        } else 
		if ( $payments_row['type'] == 2 ) {
			$pay_wmid = substr( $payments_row['purse'], 0, 5 ) . '<span style="color:#4769a3">XXX<span>';
            $pay_metod = '<span style="color:#545454">Pay</span><span style="color:#0099de">eer</span>';
		} 
		if ( $payments_row['type'] == 3 ) {
			$pay_wmid = substr( $payments_row['purse'], 0, 9 ) . '<span style="color:#4769a3">XXX<span>';
            $pay_metod = '<span style="color:#0EAC78">advcash<span>';
		}
        
        #формируем дату выплат
        $month = array( 'янв', 'фев', 'мар', 'апр', 'май', 'июн', 'июл', 'авг', 'сен', 'окт', 'ноя', 'дек' );
		
		#Достаем информацию о пользователе
		$user_payments = mysql_fetch_array( mysql_query( "SELECT id, username, avatar FROM user WHERE id = '" . $payments_row['iduser'] . "' LIMIT 1" ) );
        
        if ( date( 'd.m.Y', $payments_row['date'] ) == date( 'd.m.Y', time() ) ) {
            $pay_time = 'сегодня в ' . date( 'H:i', $payments_row['date'] );
        } else
        if ( date( 'd.m.Y', $payments_row['date'] ) == date( 'd.m.Y', time() - 86400 ) ) {
            $pay_time = 'вчера в ' . date( 'H:i', $payments_row['date'] );
        } else {
            $pay_time = ( int ) date( 'd', $payments_row['date'] ) . ' ' . $month[( int ) date( 'm', $payments_row['date'] ) - 1] . ' ' . date( 'Y', $payments_row['date'] )  . ' в ' . date( 'H:i', $payments_row['date'] );
        }
        ?>
        <tr>
            <td style="text-align: center;"><?=$pay_wmid?></td>
            <td>
			  <a href="/id<?=$user_payments['id']?>">
				<img src="/temp/avatar/<?=$user_payments['avatar']?>" class="img-circle competition-avatar-table" width="20" height="20" align="left" />
			  </a><?=$user_payments['username']?>
			</td>
            <td style="text-align: center;"><?=$pay_time?></td>
            <td style="text-align: center;"><?=$payments_row['money']?> <?=$config['valutaname']?></td>
            <td style="text-align: center;"><?=$pay_metod?></td>
        </tr>
        <?
      }
	

      ?>
    </table>
  </article>
</div>