<?php 

if($shop = $this->getShopByID((int)$this->param['id'])){
	
} else {
	$this->view(array("theme/_common/_header", "theme/errors/404", "theme/_common/_footer"), array("user" => $this->user, "shops" => $this->shops)); 
	exit();
}

if($this->user['user_group'] >= "3" or $this->user['user_id'] == $shop['user_id']) {

if($_POST['ajax'] == "saveName"){
	$shop_name = $this->escape($_POST['shop_name']);
	if($this->editShop("`shop_name` = '{$shop_name}'", $shop['shop_id'])){
		echo 1;
		exit();
	} else {
		echo 0;
		exit();
	}
} elseif($_POST['ajax'] == "changeGame"){
	$shop_game = $this->escape($_POST['shop_game']);
	if($this->editShop("`shop_game` = '{$shop_game}'", $shop['shop_id'])){
		echo 1;
		exit();
	} else {
		echo 0;
		exit();
	}
} elseif($_POST['ajax'] == "changeNotif"){
	if($shop['shop_notify'] == "1"){
		$this->editShop("`shop_notify` = '0'", $shop['shop_id']);
		echo 0;
		exit();
	} elseif($shop['shop_notify'] == "0"){
		$this->editShop("`shop_notify` = '1'", $shop['shop_id']);
		echo 1;
		exit();
	}
	
} elseif($_POST['ajax'] == "changeCommision"){
	$shop_commision = $this->escape($_POST['shop_commision']);
	if($this->editShop("`shop_commision_pay` = '{$shop_commision}'", $shop['shop_id'])){
		echo 1;
		exit();
	} else {
		echo 0;
		exit();
	}
} elseif($_POST['ajax'] == "new_secret"){
	$secret_key = md5(md5(md5(time().$shop['shop_id'])."maksa988"));
	if($this->editShop("`shop_secret_key` = '{$secret_key}'", $shop['shop_id'])){
		echo $secret_key;
		exit();
	} else {
		echo 0;
		exit();
	}
} elseif($_POST['ajax'] == "new_public"){
	$public_key = md5(md5(md5(time().$shop['shop_id'])."maksa988"));
	$public_key = $public_key{1}.$public_key{2}.$public_key{3}.$public_key{4}.$public_key{5}."-".$shop['shop_id'];
	if($this->editShop("`shop_public_key` = '{$public_key}'", $shop['shop_id'])){
		echo $public_key;
		exit();
	} else {
		echo 0;
		exit();
	}
} elseif($_POST['ajax'] == "checkURL"){
	$url = $this->escape($_POST['url']);
	if($this->checkURL($url)){
		echo 1;
		exit();
	} else {
		echo 0;
		exit();
	}
} elseif($_POST['ajax'] == "saveURL"){
	$url = $this->escape($_POST['url']);
	if($this->editShop("`shop_url` = '{$url}'", $shop['shop_id'])){
		echo 1;
		exit();
	} else {
		echo 0;
		exit();
	}
} elseif($_POST['ajax'] == "saveRURL"){
	$fail_url = $this->escape($_POST['fail_url']);
	$success_url = $this->escape($_POST['success_url']);
	if($this->editShop("`shop_fail_url` = '{$fail_url}', `shop_success_url` = '{$success_url}'", $shop['shop_id'])){
		echo 1;
		exit();
	} else {
		echo 0;
		exit();
	}
}

} else {
	echo 0;
	exit();
}

if($this->user['user_group'] >= "3") {
	$this->view(array("theme/_common/_header", "theme/project/setting", "theme/_common/_footer"), array("user" => $this->user, "shops" => $this->shops, "shop" => $shop, "items" => $items)); 
} elseif($this->user['user_id'] == $shop['user_id']) {
	$this->view(array("theme/_common/_header", "theme/project/setting", "theme/_common/_footer"), array("user" => $this->user, "shops" => $this->shops, "shop" => $shop, "items" => $items)); 
} else {
	$this->view(array("theme/_common/_header", "theme/errors/404", "theme/_common/_footer"), array("user" => $this->user, "shops" => $this->shops)); 
}