File size: 5.41Kb
<?php
// by mides, wmclub.mobi
require_once '../system/sys.php';
require_once '../system/auth_a.php';
require_once '../system/header.php';
if ($u['access'] == 1) header('location: ./');
if ($u['access'] == 2) header('location: ../loads.php?act=check');
switch ($_GET['act']) {
default:
tp('Загруз-центр');
$cats_r = mysql_query("SELECT * FROM `loads_cats` ORDER BY `name`");
while ($cat = mysql_fetch_assoc($cats_r)) {
echo '<a href="../loads.php?act=cat&id='.$cat['id'].'">'.$cat['name'].'</a> (<a href="?act=cat_edit&id='.$cat['id'].'">ред</a>)<br />';
$subcats_r = mysql_query("SELECT * FROM `loads_subcats` WHERE `id_cat` = '$cat[id]' ORDER BY `name`");
while ($subcat = mysql_fetch_assoc($subcats_r)) {
echo '- <a href="../loads.php?act=subcat&id='.$subcat['id'].'">'.$subcat['name'].'</a> (<a href="?act=subcat_edit&id='.$subcat['id'].'">ред</a>)<br />';
}
}
echo '<br /><a href="?act=file_add">Добавить файл</a><br />
<a href="../loads.php?act=check">Модерировать обменник</a><br />
<br/>
<form action="?act=cat_add" method="post" name="form">
<select name="cat">
<option value="0">Главная</option>';
$cats_r = mysql_query("SELECT * FROM `loads_cats` ORDER BY `name`");
while ($cat = mysql_fetch_assoc($cats_r)) {
echo '<option value="'.$cat['id'].'">'.$cat['name'].'</option>';
}
echo '</select><br />
Название (под)раздела:<br/><input name="name" type="text" maxlength="50" /><br />
<input name="submit" type="submit" value="Добавить"></form>';
nav('./');
break;
case 'cat_add':
if ($_POST['name']) {
$cat = intval($_POST['cat']);
$name = check($_POST['name']);
if ($cat > 0) {
mysql_query("INSERT INTO `loads_subcats` SET `id_cat` = '$cat', `name` = '$name'");
} else {
mysql_query("INSERT INTO `loads_cats` SET `name` = '$name'");
}
}
header('location: ?');
break;
case 'cat_edit':
$id = intval($_REQUEST['id']);
$cat = mysql_fetch_assoc(mysql_query("SELECT * FROM `loads_cats` WHERE `id` = '$id'"));
if ($cat['id']) {
if ($_REQUEST['ok']) {
if ($_POST['name']) {
$name = check($_POST['name']);
mysql_query("UPDATE `loads_cats` SET `name` = '$name' WHERE `id` = '$id'");
header('location: ?');
} else {
header('location: ?act=cat_edit&id='.$id);
}
} else {
tp('Редактировать раздел');
echo '<form action="?act=cat_edit&id='.$id.'&ok=1" method="post">
Название:<br /><input name="name" type="text" maxlength="50" value="'.$cat['name'].'" /><br />
<input name="submit" type="submit" value="Ok" />
</form>';
}
} else {
error('Раздел не существует.');
}
nav('?');
break;
case 'file_add':
if ($_REQUEST['ok']) {
if ($_POST['subcat'] and $_POST['name'] and $_FILES['file']['name']) {
$file = check(basename($_FILES['file']['name']));
if (!mysql_num_rows(mysql_query("SELECT `id` FROM `loads_files` WHERE `file` = '$file'"))) {
$subcat = intval($_POST['subcat']);
$name = check($_POST['name']);
$desc = check($_POST['desc']);
$author = check($_POST['author']);
$site = check($_POST['site']);
$cat = mysql_fetch_assoc(mysql_query("SELECT `id_cat` FROM `loads_subcats` WHERE `id` = '$subcat'"));
copy($_FILES['file']['tmp_name'], '../inc/loads/'.$file);
mysql_query("INSERT INTO `loads_files` SET `id_cat` = '$cat[id_cat]', `id_subcat` = '$subcat', `id_user` = '$u[id]', `name` = '$name', `desc` = '$desc', `author` = '$author', `site` = '$site', `file` = '$file', `time` = '".time()."'");
$_SESSION['info'] = 'Загружено.';
header('location: ?act=file_add');
} else {
error('Файл уже существует.');
nav('?act=file_add');
}
} else {
error('Вы не указали название, не выбрали подраздел или файл.');
nav('?act=file_add');
}
} else {
tp('Добавить файл');
if ($_SESSION['info']) echo '<b><u>'.$_SESSION['info'].'</u></b><br />';
unset($_SESSION['info']);
echo '<form action="?act=file_add&ok=1" method="post" enctype="multipart/form-data">
Выбрать подраздел*:<br /><select name="subcat">';
$cat_r = mysql_query("SELECT * FROM `loads_cats` ORDER BY `name`");
while ($cat = mysql_fetch_assoc($cat_r)) {
echo '<option value="0">'.$cat['name'].'</option>';
$subcat_r = mysql_query("SELECT * FROM `loads_subcats` WHERE `id_cat` = '$cat[id]' ORDER BY `name`");
while ($subcat = mysql_fetch_assoc($subcat_r)) {
echo '<option value="'.$subcat['id'].'">-- '.$subcat['name'].'</option>';
}
}
echo '</select><br />
Название(max50)*:<br /><input name="name" type="text" maxlength="50" /><br />
Описание:<br /><textarea name="desc" cols="" rows="4"></textarea><br />
Автор(max20):<br /><input name="author" type="text" maxlength="20" /><br />
Сайт(<del>http://</del>, max20):<br /><input name="site" type="text" maxlength="20" /><br />
Выбрать файл*:<br /><input name="file" type="file" size="file" /><br />
<input name="submit" type="submit" value="Ok" />
</form>';
nav('?');
}
break;
}
require_once '../system/tail_p.php';
?>