<?

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'];
$type = check_text( $_GET['type'] );

  if( $type == 'serf') {
	$proverka = mysql_num_rows( mysql_query( "SELECT id FROM dynlink where id = '" . $id . "' and iduser = '" . $_SESSION['iduser'] . "' LIMIT 1" ) );
	$type_send = 'serf();';
  } else
  if( $type == 'autoserf') {
	$proverka = mysql_num_rows( mysql_query( "SELECT id FROM autodynlink where id = '" . $id . "' and iduser = '" . $_SESSION['iduser'] . "' LIMIT 1" ) );
	$type_send = 'autoserf();';
  } else
  if( $type == 'test') {
	$proverka = mysql_num_rows( mysql_query( "SELECT id FROM tests where id = '" . $id . "' and iduser = '" . $_SESSION['iduser'] . "' LIMIT 1" ) );
	$type_send = 'test();';
  } else
  if( $type == 'task') {
	$proverka = mysql_num_rows( mysql_query( "SELECT id FROM tasks where id = '" . $id . "' and iduser = '" . $_SESSION['iduser'] . "' LIMIT 1" ) );
	$type_send = 'task();';
  } else
  if( $type == 'ban1') {
	$proverka = mysql_num_rows( mysql_query( "SELECT id FROM banners where id = '" . $id . "' and iduser = '" . $_SESSION['iduser'] . "' LIMIT 1" ) );
	$type_send = 'ban1();';
  } else
  if( $type == 'ban2') {
	$proverka = mysql_num_rows( mysql_query( "SELECT id FROM banners where id = '" . $id . "' and iduser = '" . $_SESSION['iduser'] . "' LIMIT 1" ) );
	$type_send = 'ban2();';
  } else
  if( $type == 'klink') {
	$proverka = mysql_num_rows( mysql_query( "SELECT id FROM klink where id = '" . $id . "' and iduser = '" . $_SESSION['iduser'] . "' LIMIT 1" ) );
	$type_send = 'klink();';
  } else
  if( $type == 'statlink') {
	$proverka = mysql_num_rows( mysql_query( "SELECT id FROM statlink where id = '" . $id . "' and iduser = '" . $_SESSION['iduser'] . "' LIMIT 1" ) );
	$type_send = 'statlink();';
  } else
  if( $type == 'chain') {
	$proverka = mysql_num_rows( mysql_query( "SELECT id FROM chain where id = '" . $id . "' and iduser = '" . $_SESSION['iduser'] . "' LIMIT 1" ) );
	$type_send = 'chain();';
  } else
  if( $type == 'vk') {
	$type_send = 'vk();';
  } else
  if( $type == 'youtube') {
	$type_send = 'youtube();';
  } else {
	$proverka = 0;
	$type_send = '();';
  } 

?>
  <div class="modal fade bd-example-modal-lg" id="modalf">
	  <div class="modal-dialog " role="document">
		<div class="modal-content">
		  <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">Удаление площадки - <?=$id?></h4>
		  </div>
		  
		  <div class="modal-body"><!--Содержимое модального окна начало-->
			<div class="arrow_d_gift"></div>
			  <div id="gif_open">
			    <? if( $proverka > 0 ) { ?>
				  <div class="wrap_body_gift">
				    Вы действительно хотите удалить рекламную площадку №<?=$id?>
				  </div>
				  <div class="div_centralizator">
				    <br/>
				    <button type="button" class="btn btn-danger btn-sm" style="height: 19px;" onclick="<?=$type_send?>">Удалить площадку?</button>
				    <br/><br/>
				  </div>
				<? } else { ?>
				  <br/><br/>
				  <div class="div_centralizator">
				    
					<div class="alert alert-danger" role="alert">
					  <b>Ошибка!</b> Рекламная площадка удалена или не принадлежит вам.
					</div>
				  </div>
				  <br/><br/>
				<? } ?>
			  </div>
			  
			  <div class="error_modal_ultimate" > </div>
			  <p style="display: none;" id="success_text"><span class="glyphicon glyphicon-info-sign"></span> Площадка удалена! Можете закрыть окно.</p>
		  </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 serf() {
	  $.post('ajax.php?func=deldyn',{
		id : <?=$id?>
	  }, function(data){
		if (data == 1){
		  $("#gif_open").fadeOut(300);
		  $("#send_walls_gift").fadeOut(300);
		  $("#success_text").fadeIn(800);
		  Page.Go('mdyn');
		} else {
		  $('.error_modal_ultimate').fadeIn().html(data);
		  setTimeout(function() {
			$('.error_modal_ultimate').fadeOut().html('&nbsp;');
		  }, 4000);
		}
	  });
	  return false;
	}

	function autoserf() {
	  $.post('ajax.php?func=delautodyn',{
		id : <?=$id?>
	  }, function(data){
		if (data == 1){
		  $("#gif_open").fadeOut(300);
		  $("#send_walls_gift").fadeOut(300);
		  $("#success_text").fadeIn(800);
		  Page.Go('mautodyn');
		} else {
		  $('.error_modal_ultimate').fadeIn().html(data);
		  setTimeout(function() {
			$('.error_modal_ultimate').fadeOut().html('&nbsp;');
		  }, 4000);
		}
	  });
	  return false;
	}

	function test() {
	  $.post('ajax.php?func=deltests',{
		id : <?=$id?>
	  }, function(data){
		if (data == 1){
		  $("#gif_open").fadeOut(300);
		  $("#send_walls_gift").fadeOut(300);
		  $("#success_text").fadeIn(800);
		  Page.Go('mtests');
		} else {
		  $('.error_modal_ultimate').fadeIn().html(data);
		  setTimeout(function() {
			$('.error_modal_ultimate').fadeOut().html('&nbsp;');
		  }, 4000);
		}
	  });
	  return false;
	}

	function task() {
	  $.post('ajax.php?func=deltasks',{
		id : <?=$id?>
	  }, function(data){
		if (data == 1){
		  $("#gif_open").fadeOut(300);
		  $("#send_walls_gift").fadeOut(300);
		  $("#success_text").fadeIn(800);
		  Page.Go('mtasks');
		} else {
		  $('.error_modal_ultimate').fadeIn().html(data);
		  setTimeout(function() {
			$('.error_modal_ultimate').fadeOut().html('&nbsp;');
		  }, 4000);
		}
	  });
	  return false;
	}

	function ban1() {
	  $.post('ajax.php?func=delban468x60',{
		id : <?=$id?>
	  }, function(data){
		if (data == 1){
		  $("#gif_open").fadeOut(300);
		  $("#send_walls_gift").fadeOut(300);
		  $("#success_text").fadeIn(800);
		  Page.Go('mban468x60');
		} else {
		  $('.error_modal_ultimate').fadeIn().html(data);
		  setTimeout(function() {
			$('.error_modal_ultimate').fadeOut().html('&nbsp;');
		  }, 4000);
		}
	  });
	  return false;
	}

	function ban2() {
	  $.post('ajax.php?func=delban2x3',{
		id : <?=$id?>
	  }, function(data){
		if (data == 1){
		  $("#gif_open").fadeOut(300);
		  $("#send_walls_gift").fadeOut(300);
		  $("#success_text").fadeIn(800);
		  Page.Go('mautodyn');
		} else {
		  $('.error_modal_ultimate').fadeIn().html(data);
		  setTimeout(function() {
			$('.error_modal_ultimate').fadeOut().html('&nbsp;');
		  }, 4000);
		}
	  });
	  return false;
	}

	function klink() {
	  $.post('ajax.php?func=delklink',{
		id : <?=$id?>
	  }, function(data){
		if (data == 1){
		  $("#gif_open").fadeOut(300);
		  $("#send_walls_gift").fadeOut(300);
		  $("#success_text").fadeIn(800);
		  Page.Go('mklink');
		} else {
		  $('.error_modal_ultimate').fadeIn().html(data);
		  setTimeout(function() {
			$('.error_modal_ultimate').fadeOut().html('&nbsp;');
		  }, 4000);
		}
	  });
	  return false;
	}

	function statlink() {
	  $.post('ajax.php?func=delstatlink',{
		id : <?=$id?>
	  }, function(data){
		if (data == 1){
		  $("#gif_open").fadeOut(300);
		  $("#send_walls_gift").fadeOut(300);
		  $("#success_text").fadeIn(800);
		  Page.Go('mstatlink');
		} else {
		  $('.error_modal_ultimate').fadeIn().html(data);
		  setTimeout(function() {
			$('.error_modal_ultimate').fadeOut().html('&nbsp;');
		  }, 4000);
		}
	  });
	  return false;
	}

	function chain() {
	  $.post('ajax.php?func=delchain',{
		id : <?=$id?>
	  }, function(data){
		if (data == 1){
		  $("#gif_open").fadeOut(300);
		  $("#send_walls_gift").fadeOut(300);
		  $("#success_text").fadeIn(800);
		  Page.Go('mchain');
		} else {
		  $('.error_modal_ultimate').fadeIn().html(data);
		  setTimeout(function() {
			$('.error_modal_ultimate').fadeOut().html('&nbsp;');
		  }, 4000);
		}
	  });
	  return false;
	}

	function vk() {
	  $.post('ajax.php?func=delautodyn',{
		id : <?=$id?>
	  }, function(data){
		if (data == 1){
		  $("#gif_open").fadeOut(300);
		  $("#send_walls_gift").fadeOut(300);
		  $("#success_text").fadeIn(800);
		  Page.Go('mautodyn');
		} else {
		  $('.error_modal_ultimate').fadeIn().html(data);
		  setTimeout(function() {
			$('.error_modal_ultimate').fadeOut().html('&nbsp;');
		  }, 4000);
		}
	  });
	  return false;
	}

	function youtube() {
	  $.post('ajax.php?func=delautodyn',{
		id : <?=$id?>
	  }, function(data){
		if (data == 1){
		  $("#gif_open").fadeOut(300);
		  $("#send_walls_gift").fadeOut(300);
		  $("#success_text").fadeIn(800);
		  Page.Go('mautodyn');
		} else {
		  $('.error_modal_ultimate').fadeIn().html(data);
		  setTimeout(function() {
			$('.error_modal_ultimate').fadeOut().html('&nbsp;');
		  }, 4000);
		}
	  });
	  return false;
	}

  </script>