<?php
$title = 'Страница товара';
include_once($_SERVER["DOCUMENT_ROOT"].'/php/style/head.php');
$_GET['id'] = abs(intval($_GET['id']));
$query = $db->query("SELECT * FROM `products` WHERE `id`='".$_GET['id']."'");
if($query->num_rows==0){
	header('location:/main');
}
$product = $query->fetch_assoc();
$cat = $db->query("SELECT * FROM `categories` WHERE `id`='".$product['id_categorie']."'")->fetch_assoc();
?>
<div class="container theme-showcase" role="main">
	<div class="jumbotron">
		<h1><?=output($product['name'])?></h1>

		<div class="row">
				<?
				$query = $db->query("SELECT * FROM `products_images` WHERE `id_product`=".$_GET['id']."");
				while($img = $query->fetch_assoc()){
					?>
							<div class="col-xs-2 col-md-2">
		    					<div class="thumbnail">
		      						<a href="/files/images/products/<?=output($img['image'])?>">
										<img src="/files/images/products/<?=output($img['image'])?>">
									</a>
		    					</div>
		  					</div>					<?
				}?>
		</div>
		<p>
			<h3>Стоимость <?=$product['price']?> руб.</h3>
			<?if(isUser()){?>
				<a class="btn btn-primary btn-lg" href="/cart/add/<?=$product['id']?>" role="button">Добавить в корзину <span class="badge"><?=$product['in_stock']?> шт. в наличии</span></a>
			<?}?>
			<?if($user['admin'] >= 2){
				?>
				<a class="btn btn-warning btn-lg" href="/admin/products/edit/<?=$_GET['id']?>" role="button">Редактировать товар</a>
				<a class="btn btn-danger btn-lg" href="/admin/products/delete/<?=$_GET['id']?>" role="button">Удалить товар</a>
				<?
			}?>
		</p>
	</div>
	<div class="page-header">
		<ol class="breadcrumb">
			<li><a href="/categories">Разделы</a></li>
			<?
	  			if($cat['podkat'] != 0){
	  				$tcat = $cat['podkat'];
	  				while($tcat != 0){
	  					$kcat = $db->query("SELECT * FROM `categories` WHERE `id`='".$tcat."'")->fetch_assoc();
	  					?>
	  					<li><a href="/categories/<?=$kcat['id']?>"><?=output($kcat['name'])?></a></li>
	  					<?php
	  					$tcat = $kcat['podkat'];
	  				}
	  			}
	  			?>
	  		<li><a href="/categories/<?=$cat['id']?>"><?=output($cat['name'])?></a></li>
			<li class="active"><?=output($product['name'])?></li>
		</ol>
	</div>
	<ul class="nav nav-pills nav-justified">
		<li role="presentation" class="active" style="border-radius: 0px;"><a href="#">Описание</a></li>
		<li role="presentation"><a href="/product/<?=$_GET['id']?>/comments">Комментарии <span class="badge"><?=$db->query("SELECT `id` FROM `products_comments` WHERE `id_product`=".$_GET['id']."")->num_rows?></span></a></li>
		<li role="presentation"><a href="/product/<?=$_GET['id']?>/reviews">Отзывы <span class="badge"><?=$db->query("SELECT `id` FROM `products_reviews` WHERE `id_product`=".$product['id']."")->num_rows?></span></a></li>
	</ul>
	<p><div class="well well-lg"><?=output($product['description'])?></div></p>
</div>
<?php
include_once($_SERVER["DOCUMENT_ROOT"].'/php/style/head.php');
?>