<?
#Проверяем способ вызова файла
if ( !defined( 'MISOFT_ADMIN_DIRR' ) ) exit();
  
#Если статус не администратора, или в не сесии авторизации, останавливаем выполнение скриптов php
if ( !isset( $_SESSION['iduser'] ) or $config_user['account'] != 5 ) { exit(); }

### Заказ выплат за последние 7 дней.
  $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;

  $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;
  }

### Пополнения с ЭПС за последние 7 дней.
  $view_adv1 = mysql_fetch_array( mysql_query( "SELECT SUM(price) as sum FROM history_reklama_pay WHERE date >= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:01' ) ) . "' and date <= '" . ( strtotime( date('Y').'-'.date('m').'-'.date('d').' 00:00' ) + 86400 ) . "'" ) );

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

  $view_adv3 = mysql_fetch_array( mysql_query( "SELECT SUM(price) as sum FROM history_reklama_pay 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 ) . "'" ) );

  $view_adv4 = mysql_fetch_array( mysql_query( "SELECT SUM(price) as sum FROM history_reklama_pay 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 ) . "'" ) );

  $view_adv5 = mysql_fetch_array( mysql_query( "SELECT SUM(price) as sum FROM history_reklama_pay 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 ) . "'" ) );

  $view_adv6 = mysql_fetch_array( mysql_query( "SELECT SUM(price) as sum FROM history_reklama_pay 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 ) . "'" ) );

  $view_adv7 = mysql_fetch_array( mysql_query( "SELECT SUM(price) as sum FROM history_reklama_pay 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( $view_adv1['sum'] ) ) $view_adv1['sum'] = 0;
  if ( empty( $view_adv2['sum'] ) ) $view_adv2['sum'] = 0;
  if ( empty( $view_adv3['sum'] ) ) $view_adv3['sum'] = 0;
  if ( empty( $view_adv4['sum'] ) ) $view_adv4['sum'] = 0;
  if ( empty( $view_adv5['sum'] ) ) $view_adv5['sum'] = 0;
  if ( empty( $view_adv6['sum'] ) ) $view_adv6['sum'] = 0;
  if ( empty( $view_adv7['sum'] ) ) $view_adv7['sum'] = 0;
  
### Денег на проекте
  #сумма рекламных площадок
  $area_sum_dynlink = mysql_fetch_array( mysql_query( "SELECT SUM(balance) as sum FROM dynlink" ) );
  $area_sum_autodynlink = mysql_fetch_array( mysql_query( "SELECT SUM(balance) as sum FROM autodynlink" ) );
  $area_sum_klink = mysql_fetch_array( mysql_query( "SELECT SUM(balance) as sum FROM klink" ) );
  $area_sum_banners = mysql_fetch_array( mysql_query( "SELECT SUM(balance) as sum FROM banners" ) );
  $area_sum_tests = mysql_fetch_array( mysql_query( "SELECT SUM(balance) as sum FROM tests" ) );
  $area_sum_tasks = mysql_fetch_array( mysql_query( "SELECT SUM(balance) as sum FROM tasks" ) );
  $area_sum_chain = mysql_fetch_array( mysql_query( "SELECT SUM(balance) as sum FROM chain" ) );
  $area_sum_stat = mysql_fetch_array( mysql_query( "SELECT SUM(balance) as sum FROM statlink" ) );
  $area_sum = $area_sum_autodynlink['sum'] + $area_sum_dynlink['sum'] + $area_sum_klink['sum'] + $area_sum_banners['sum'] + $area_sum_tests['sum'] + $area_sum_tasks['sum'] + $area_sum_chain['sum'] + $area_sum_stat['sum'];
  
  #сумма баланса пользователей
  $user_sum = mysql_fetch_array( mysql_query( "SELECT SUM(money) as sum FROM user" ) );
  $user_sum_adv = mysql_fetch_array( mysql_query( "SELECT SUM(adv_money) as sum FROM user" ) );
  
### Количество рекламных площадок
  #сумма рекламных площадок
  $rows_sum_tddynlink = mysql_query( "SELECT id FROM dynlink WHERE paused = '1' AND testdrive = '1' " );
  $rows_sum_dynlink = mysql_query( "SELECT id FROM dynlink WHERE paused = '1' " );
  $rows_sum_autodynlink = mysql_query( "SELECT id FROM autodynlink WHERE paused = '1' " );
  $rows_sum_klink = mysql_query( "SELECT id FROM klink WHERE paused = '1' " );
  $rows_sum_banners = mysql_query( "SELECT id FROM banners WHERE paused = '1' " );
  $rows_sum_tests = mysql_query( "SELECT id FROM tests WHERE paused = '1' " );
  $rows_sum_tasks = mysql_query( "SELECT id FROM tasks WHERE paused = '1' " );
  $rows_sum_chain = mysql_query( "SELECT id FROM chain WHERE paused = '1' " );
  $rows_sum_stat = mysql_query( "SELECT id FROM statlink WHERE paused = '1' " );
  
  
?>