<?php 

if($shop = $this->getShopByID((int)$this->param['id'])){
	if($_POST['ajax'] == "turn_wm"){
		if($shop['shop_webmoney'] == 1){
			if($this->editShop("`shop_webmoney` = '0'", $shop['shop_id'])){
				echo "WebMoney отключен.";
				exit();
			} else {
				echo 0;
				exit();
			}
		} else {
			if($this->editShop("`shop_webmoney` = '1'", $shop['shop_id'])){
				echo "WebMoney подключен.";
				exit();
			} else {
				echo 0;
				exit();
			}
		}
	}

	if($_POST['ajax'] == "turn_rb"){
		if($shop['shop_robokassa'] == 1){
			if($this->editShop("`shop_robokassa` = '0'", $shop['shop_id'])){
				echo "Робокасса отключена.";
				exit();
			} else {
				echo 0;
				exit();
			}
		} else {
			if($this->editShop("`shop_robokassa` = '1'", $shop['shop_id'])){
				echo "Робокасса подключена.";
				exit();
			} else {
				echo 0;
				exit();
			}
		}
	}
		if($_POST['ajax'] == "turn_zp"){
		if($shop['shop_zpayment'] == 1){
			if($this->editShop("`shop_zpayment` = '0'", $shop['shop_id'])){
				echo "Z-Payment отключена.";
				exit();
			} else {
				echo 0;
				exit();
			}
		} else {
			if($this->editShop("`shop_zpayment` = '1'", $shop['shop_id'])){
				echo "Z-Payment подключена.";
				exit();
			} else {
				echo 0;
				exit();
			}
		}
	}
} else {
	$this->view(array("theme/_common/_header", "theme/errors/404", "theme/_common/_footer"), array("user" => $this->user, "shops" => $this->shops)); 
	exit();
}

$stats[1] = $this->getShopStatsWeek("1", (int)$this->param['id']);
$stats[2] = $this->getShopStatsWeek("0", (int)$this->param['id']);
$stats[3] = $this->getBalance("today", (int)$this->param['id']); // $stats[3][0]['sum']
$stats[4] = $this->getBalance("week", (int)$this->param['id']); // $stats[4][0]['sum']
array_shift($stats[4]);

// dd($stats[4][0]['sum']);

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