<?php
$id = isset($_GET['id']) ? abs((int)$_GET['id']) : false;
if (empty($id)) {
header ('location: /');
exit;
}
$query = DB :: $dbs -> query ("SELECT * FROM `magazin_file` WHERE `id`= ?", [$id]);
if ($query -> rowCount () == 0) {
header ('location: /');
exit;
}
$file = $query -> fetch ();
$pr = DB :: $dbs -> queryFetch ("SELECT * FROM `magazin_pr` WHERE `id`= ?", [$file['id_pr']]);
$r = DB :: $dbs -> queryFetch ("SELECT * FROM magazin_r WHERE id = ?", [$file['id_r']]);
$title->SetTitle('Маркет - Товар ' . $file['name']);
$title->GetHeader();
echo'<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-widgets"></i><a href="/"style="text-decoration:none; color:white;"> Главная</a> :: <a href="/market"style="text-decoration:none; color:white;"> Маркет</a> :: <a href="/market/kat/'.$r['id'].'"style="text-decoration:none; color:white;">' . $r['name'].'</a> :: <a href="/market/dir/'.$pr['id'].'"style="text-decoration:none; color:white;">' . $pr['name'].'</a> :: ' . $file['name'].'</div></div></div>';
echo'<div class="t-body"><div class="list-group lg-alt">';
if ($file['user_id'] == $b['id'] || $b['level'] >=3) {
echo '<div class="list-group-item media"><i class="zmdi zmdi-shuffle"></i>   '.($file['block_file'] == 0 ? '<a href="/market/file/'.$id.'?da">[Приостановить продажу]</a>':'<a href="/market/file/'.$id.'?un">[Возобновить продажу]</a>').'</div>';
}
if ($b['level'] >=3) {
echo '<div class="list-group-item media"><i class="zmdi zmdi-shuffle"></i>   '.($file['block'] == 0 ? '<a href="/market/file/'.$id.'?block">[Блокировать товар]</a>':'<a href="/market/file/'.$id.'?unblock">[Разблокировать товар]</a>').'</div>';
}
echo'</div></div>';
if ($b['level'] >= 3) {
if (isset($_POST['block'])) {
$block_text = check($_POST['block_text']);
if (empty($block_text)) {
err('Введите причину!');
} else {
$mess = 'Ваш товар <a href="/market/file/'.$id.'">'.$file['name'].'</a> заблокирован администратором '.Nick($b['id']).' по причине [b]'.$block_text.'[/b]!';
jurnal($file['user_id'],$mess,5);
DB::$dbs->query("UPDATE magazin_file SET block = ?, block_text = ?, block_who = ? WHERE id = ? LIMIT 1", [1,$block_text,$b['id'],$id]);
header('location: /market/file/'.$id);
die();
}
}
if (isset($_GET['unblock'])) {
DB::$dbs->query("UPDATE magazin_file SET block = ?, block_text = ?, block_who = ? WHERE id = ? LIMIT 1", [0,NULL,NULL,$id]);
header('location: /market/file/'.$id);
die();
}
if (isset($_GET['block'])) {
echo '<div class="list-group-item media"><form action="/market/file/'.$id.'?block" method="POST">Причина блокировки (max.: 250):<br/><br/>';
quickpaste('text');
quickpanel();
echo'<br/><br/><textarea name="block_text" class="form-control" rows="8"></textarea><br/><input type="submit" class="btn btn-primary" name="block" value="Дальше"/></form></div>';
}
}
if ($file['block'] == 1) {
echo '<div class="list-group-item media">'.Nick($file['block_who']).' заблокировал товар по причине: <b>'.text($file['block_text']).'</b></div>';
$title->GetMenu();
$title->GetFooter();
die();
}
if ($file['user_id'] == $b['id'] || $b['level'] >= 3) {

if (isset($_GET['da'])) {
if ($file['block_file'] == 1) {
header('location: /market/file/'.$id);
die();
}
$mess = 'Продажа Вашего товар <a href="/market/file/'.$id.'">'.$file['name'].'</a> временно заблокирована!';
jurnal($file['user_id'],$mess,5);
DB::$dbs->query("UPDATE `magazin_file` SET `block_file` = ? WHERE `id` = ? LIMIT 1", [1,$id]);
header('location: /market/file/'.$id);
die();
}
if (isset($_GET['un'])) {
if ($file['block_file'] == 0) {
header('location: /market/file/'.$id);
die();
}
DB::$dbs->query("UPDATE magazin_file SET block_file = ? WHERE id = ? LIMIT 1", [0,$id]);
$mess = 'Продажа Вашего товар <a href="/market/file/'.$id.'">'.$file['name'].'</a> возобновлена!';
jurnal($file['user_id'],$mess,5);
header('location: /market/file/'.$id);
die();
}
}
if (isset($_GET['corz'])) {
if (DB::$dbs->querySingle("SELECT count(id) FROM magazin_korz WHERE file = ? AND user_id = ?", [$id,$b['id']]) == 0) {
DB::$dbs->query("INSERT INTO magazin_korz SET file = ?, user_id = ?, time = ?", [$id,$b['id'],time()]);
echo '<div class="alert alert-success">Товар добавлен в вашу корзину!</div>';
}
}

$array = DB::$dbs->query("SELECT * FROM magazin_screen WHERE file = ? ORDER BY id DESC", [$id]);
if ($array->rowCount()>0) {
echo'<div class="list-group-item media"><center> ';
while($arr = $array->fetch()){
echo '<a href="/files/mag_screen/'.$arr['screen'].'"> <img src="/files/mag_screen/'.$arr['screen'].'" alt="*" style="max-width:100%; border-bottom-left-radius: 20px; border-bottom-right-radius: 20px; border-top-right-radius: 20px; border-top-left-radius: 20px;"/></a></a> ';
}
echo '<center></div>';
}
echo '<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-comments"></i> Информация ' . $file['name'].'</div></div></div>';
echo '<div class="list-group-item media"><i class="zmdi zmdi-comment"></i> Название:  <b>'.text($file['name']).'</b></div>
      <div class="list-group-item media"><i class="zmdi zmdi-account"></i> Загрузил: '.Nick($file['user_id']).' ('.vr($file['time']).')</div>
      <div class="list-group-item media"><i class="zmdi zmdi-comments"></i> <b>Описание:</b> '.text($file['opis']).'</div>
      <div class="list-group-item media"><i class="zmdi zmdi-upload"></i> Вес файла:<b> '.get_size(filesize(ROOT.'files/mag_file/'.$file['file'])).'</b></div>
      <div class="list-group-item media"><i class="zmdi zmdi-upload"></i> Стоимость: <b>'.$file['price'].' р.</b> /  продает '.($file['kopii'] !=0 ? $file['kopii'] : 'Неограниченно').' ('.$file['prodano'].' купили)</div>
      <div class="list-group-item media"><i class="zmdi zmdi-fire"></i> <b>'.($file['prava'] == 1 ? 'С правами на перепродажу':'Без прав на перепродажу').'</b></div>
      <div class="list-group-item media"><i class="zmdi zmdi-shopping-cart-plus"></i> Добавили в корзину: '.DB::$dbs->querySingle("SELECT COUNT(id) FROM magazin_korz WHERE file = ?", [$id]).'';
if (isset($b)) {
if (DB::$dbs->querySingle("SELECT count(id) FROM magazin_korz WHERE file = ? AND user_id = ?", [$id,$b['id']]) == 0) {
echo '<a href="/market/file/'.$id.'?corz"> [Добавить]</a>';
} }
echo '</div>';
if (isset($b)) {
if ($file['user_id'] != $b['id']) {
echo'<div class="list-group-item media"><center> ';
if(DB::$dbs->querySingle("SELECT count(id) FROM `magazin_mybuy` WHERE `user_id` = ? AND `file` = ?", [$b['id'],$id]) >0) {
echo '<a href="/market/buy/load/'.$id.'"class="btn btn-primary"style="text-decoration:none; color:black;">[Скачать '.text($file['name']).']</a></div>';
} else {
if ($file['kopii']==0) {
echo ($file['block_file'] == 0 ? '<a href="/market/buy/'.$file['id'].'"class="btn btn-primary"style="text-decoration:none; color:black;">Купить '.text($file['name']).'</a>':'Продажа приостановлена!').'<br/>';
} elseif($file['kopii']>$file['prodano']) {
echo ($file['block_file'] == 0 ? '<a href="/market/buy/'.$file['id'].'"class="btn btn-primary"style="text-decoration:none; color:black;">Купить '.text($file['name']).'</a>':'Продажа приостановлена!').'<br/>';
}
echo'</center></div>';
}
if ($file['kopii'] != 0 && $file['kopii']<=$file['prodano']) {
err('Все копии данного товара проданы!');
}
}
}
if ($b['level']>4){ echo '<div class="list-group-item media"><a href="/market/zip/'.$file['id'].'"><i class="zmdi zmdi-shield-security"></i> <b>Просмотр архива</b></a></div>';}
$wm = DB::$dbs->queryFetch("SELECT * FROM `blogger` WHERE `id`=?", [$file['user_id']]);
echo '<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-format-list-bulleted"></i> Реквизиты ' . $wm['nick'] . '</div></div></div>';
if($wm['wmid'] == NULL){
echo '<div class="error">WMID не заполнен! Не рекомендуем проводить денежные операции! </div>';
} else {
echo '<div class="list-group-item media">
&#187;   WMID: <a href="https://passport.webmoney.ru/asp/certView.asp?wmid='.$wm['wmid'].'">'.$wm['wmid'].' </a><br/>
&#187;   BL <img src="https://bl.wmtransfer.com/img/bl/'.$wm['wmid'].'?w=35&h=18" /><br/>
&#187;   Претензии/Отзывы: <img src="http://arbitrage.webmoney.ru/xml/AL.aspx?wmid='.$wm['wmid'].'" /><br/>
&#187;   WMR: <a href="http://search.wmtransfer.com/?w=w&q=R'.$wm['wmr'].'">'.$wm['wmr'].'</a><br/>
&#187;   <b>'.($wm['wm']==0?'<font color="red">WMID Не подтвержден!</font>':'<font color="green">WMID подтвержден!</font>').'</b></div>';
echo '<div class="list-group-item media"><a href="/info/rating.html?id='.$wm['id'].'"><i class="zmdi zmdi-shuffle"></i>  Отзывы о ' . $wm['nick'] . ': (<b><font color="green">'.DB :: $dbs -> querySingle("SELECT COUNT(id) FROM arbitage WHERE user_id = ? AND status = ? AND type = ?",[$wm['id'],0,1]).'</font></b>/<b><font color="red">'.DB :: $dbs -> querySingle("SELECT COUNT(id) FROM arbitage WHERE user_id = ? AND status = ? AND type = ?",[$wm['id'],0,2]).'</font></b>)</div></a>';
}

if ($file['user_id']==$b['id']) {
echo '<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-format-list-bulleted"></i> Действие с товаром</div></div></div><div class="t-body"><div class="list-group lg-alt">
<div class="list-group-item media"><a href="/market/whobuy/'.$id.'"><i class="zmdi zmdi-shuffle"></i> Покупатели</a></div>
<div class="list-group-item media"><a href="/market/screen/'.$id.'"><i class="zmdi zmdi-shuffle"></i> Параметры скриншотов</a></div>
<div class="list-group-item media"><a href="/market/refile/'.$id.'"><i class="zmdi zmdi-shuffle"></i> Параметры файла</a></div></div></div>';
}

echo '<div class="tile"><div class="t-header th-alt bg-teal"><div class="th-title"><i class="zmdi zmdi-comments"></i> Обсуждение товара</div></div></div>';
if ($b == true){ 
if (isset($_GET['delkom'])) {
if ($b['level'] < 2){
header('Location: /');
die();
}
DB::$dbs->query("DELETE FROM magazin_komm WHERE id = ?", [abs((int)$_GET['delkom'])]);
header('location: /market/file/'.$id);
die();
}
if (isset($_POST['ok'])) {
$msg = check($_POST['msg']);
if (DB::$dbs->querySingle("SELECT count(id) FROM `magazin_komm` WHERE `text` =? AND `user_id` = ?", [$msg,$b['id']]) > 0) {
$err = 'Вы это уже писали!!!';
} elseif (empty($msg)) {
$err = 'Введите комментарий';
}
if (empty($err)) {
DB::$dbs->query("INSERT INTO magazin_komm SET file = ?, text = ?, time = ?, user_id = ?", [$id,$msg,time(),$b['id']]);
} else {
err('Ошибка');
}
}
if (isset($_GET['otv'])) {
$otv = abs(intval($_GET['otv']));
$u = DB::$dbs->queryFetch("SELECT * FROM blogger WHERE id = ? LIMIT 1", [$otv]);
if (empty($u['id']) && $u['id']==$b['id']){
header('location:?');
}
$st = $u['nick'].', ';
} else {
$st = '';
}

echo '<div class="list-group-item media"><form action="/market/file/'.$id.'" method="POST"><br/>';
quickpaste('text');
quickpanel();
echo'<br/><br/><textarea class="form-control" rows="8" name="msg">'.$st.'</textarea><br/><input type="submit" name="ok" class="btn btn-primary" value="Добавить"/></form></div>';
} else {echo'<div class="list-group-item media">Только зарегистрированные пользователи могут оставлять комментарии. <a href= "/login" >Войдите</a>, пожалуйста.</div>';}
$k_post = DB::$dbs->querySingle("SELECT COUNT(id) FROM `magazin_komm` WHERE `file` = ?", [$id]);
if ($k_post == 0) {
err('Комментариев нет!');
}
$num = 10;
$k_page = k_page($k_post, $num);
$page = page($k_page);
$start = $num*$page-$num;
$array = DB::$dbs->query("SELECT * FROM `magazin_komm` WHERE `file` = ? ORDER BY time DESC LIMIT $start,$num",[$id]);
while($arr = $array -> fetch()) {
$del = ($b['level']>=2 ? '[<a href="/market/file/'.$id.'?delkom='.$arr['id'].'">Удл</a>] ':NULL);
echo '<div class="list-group-item media">'.$del . Nick($arr['user_id']).' ('.vr($arr['time']).'] '. (($arr['user_id'] != $b['id']) ? '[<a href="/market/file/'.$id.'?otv='.$arr['user_id'].'">Отв</a>]':NULL).' </br>'.text($arr['text']) .'</div>';
}
if ($k_page > 1) {
str('?id='.$id.'&',$k_page,$page);
}
?>