<?php
include_once '../../sys/inc/start.php';
include_once '../../sys/inc/compress.php';
include_once '../../sys/inc/sess.php';
include_once '../../sys/inc/home.php';
include_once '../../sys/inc/settings.php';
include_once '../../sys/inc/db_connect.php';
include_once '../../sys/inc/ipua.php';
include_once '../../sys/inc/fnc.php';
include_once '../../sys/inc/user.php';

if(isset($_GET['id'])){
	$id = intval($_GET['id']);
	}else{
		header("Location: /index.php");
		}

$set['title']='Удаление &amp; '.$_SERVER['HTTP_HOST'];

include_once '../../sys/inc/thead.php';

title();
aut();

echo '<div class="menu">';

if(!isset($user)){
	echo '<div class="err">Доступ закрыт.</div>';
	}else if($id==0 || $id<0){
		echo '<div class="err">Доступ закрыт.</div>';
		}else if(isset($user) && $user['level']<4){
			echo '<div class="err">Доступ закрыт.</div>';
			}else{

if($_GET['act']=='dir'){

$q = mysql_query("SELECT * FROM `smiles_spis` WHERE `id_dir` = '".$id."'");
while($sm = mysql_fetch_array($q)){
	unlink(H.'style/smiles/'.$sm['name'].'.gif');
	}

$q = mysql_query("SELECT * FROM `smiles_spis` WHERE `id_dir` = '".$id."'");
while($sm = mysql_fetch_array($q)){
	mysql_query("DELETE FROM `smiles_spis` WHERE `id_dir` = '".$id."'");
	}

mysql_query("DELETE FROM `smiles_dir` WHERE `id` = '".$id."'");
mysql_query("OPTIMIZE TABLE `smiles_spis`, `smiles_dir`");
header("Location: index.php?dir");

}else if($_GET['act']=='smile'){
$smile = mysql_fetch_array(mysql_query("SELECT * FROM `smiles_spis` WHERE `id` = '".$id."'"));
unlink(H.'style/smiles/'.$smile['name'].'.gif');
mysql_query("DELETE FROM `smiles_spis` WHERE `id` = '".$id."' LIMIT 1");
mysql_query("OPTIMIZE TABLE `smiles_spis`");
header("Location: index.php?smi");

}else{
	echo '<div class="err">Неверный ввод</div>';
	}
	}

echo '</div>';
include_once '../../sys/inc/tfoot.php';
?>