<?
/*
# by gold_spaces
*/
include '../../connect.php';
include 'func.php';
include '../../head.php';
$id = abs(intval($_GET['id']));
$kat = mysql_fetch_assoc(mysql_query("SELECT * FROM `down_r` WHERE `id` = '$id' LIMIT 1"));
if(empty($kat)){msg('раздел не найден!');include'../foot.php';exit();}
echo '<div class="title">Зона Обмена</div>';
$all = mysql_result(mysql_query("SELECT count(id) FROM `down_pr` WHERE `id_r` = '$id'"),0);
$view = mysql_query("SELECT * FROM `down_pr` WHERE `id_r` = '$id' ORDER BY `id` ASC");
if($all==0){echo'<div class="div">Подкатегорий нет</div>';}
while($a = mysql_fetch_assoc($view)){
$count = mysql_result(mysql_query("SELECT count(id) from `down` WHERE `id_pr` = '$a[id]'"),0);
echo '<div class="div"><a href="list.php?id='.$a['id'].'"><img src="/ico/pap.gif" alt="*"/> '.$a['name'].' ('.$count.')</a></div>';
}
if($u['admin']==1){
echo'<div class="div"><a href="?id='.$id.'&add">Добавить подкатегорию</a></div>';
if(isset($_GET['add'])){
echo'<div class="div">Добавление подкатегории</div>';
echo '<div class="main"><form action="?id='.$id.'&add&ok" method="post">Название подкатегории:<br/><input type="text" name="name"/><br/>
<input type="submit" value="Создать подкатегорию"/></form></div>';
}
if(isset($_GET['ok'])){
$namen = retrans(del($_POST['name']));
$name = check($_POST['name']);
$namen = $kat['map'].'/'.$namen;
if(is_dir('files/'.$namen)){
echo'<div class="main">Такая папка уже существует!</div>';
}elseif(empty($name) or empty($namen) or mysql_result(mysql_query("SELECT count(*) from `down_pr` where `name` = '$name' and `namen` like '".$kat['namen']."'"),0)>=1){echo'<div class="main">Ошибка!</div>';}else{
mysql_query("INSERT INTO `down_pr` set `name` = '$name', `namen` = '$namen', `id_r` = '$id'");
mkdir('files/'.$kat['namen'].'/'.$namen, 0777);
header('location:?id='.$id);
}
}
}
include '../../foot.php';
?>