<?
if($ku['status']==3)
if(isset($_GET['add']))
{
if(isset($_POST['submited']) && isset($_POST['name']) && isset($_FILES['file']))
{
$name=$_POST['name'];
$name=str_replace(' ','',$name);
$q=explode(',',$name);
$count=0;
$name=NULL;
foreach($q as $key => $value)
{
if($value!=NULL){$name=($name!=NULL?$name.",":null)."$value";$count++;}
}
$img=$_FILES['file']['name'];
$type=$_FILES['file']['type'];
if ($type!='image/jpeg' && $type!='image/jpg' && $type!='image/gif' && $type!='image/png')err_game('Это не картинка');
elseif($count==0)err_game("Введите хоть одно название.");
else
{
mysql_query("INSERT INTO `kolhoz_smiles` SET `name` = '$name', `img` = '$img'");
$tmp = $_FILES['file']['tmp_name'];
move_uploaded_file($tmp, 
"img/smiles/$img");
chmod("img/smiles/$img",0777);
header("Location: ?admin=smiles");
exit;
}
}
?>
<div class="event">
<h1>Добавить</h1>
</div>
<div class="content">
<ul class="blockings">
<?
echo "<form method='post' enctype='multipart/form-data'>";
echo "Названия (через запитую):<br/>";
echo "<input type='text' name='name'><br/>";
echo "Изображение:<br/>";
echo "<input type='file' name='file'><br/>";
echo "<input type='submit' name='submited' value='Добавить'><br/>";
echo "</form></ul>";
include_once 'inc/foot.php';
}
elseif(isset($_GET['delete']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_smiles` WHERE `id` = '".intval($_GET['delete'])."'"),0)!=0 && $ku['status']==3)
{
mysql_query("DELETE FROM `kolhoz_smiles` WHERE `id` = '".intval($_GET['delete'])."'");
unlink("img/smiles/".mysql_result(mysql_query("SELECT `img` FROM `kolhoz_smiles` WHERE `id` = '".intval($_GET['delete'])."'"),0));
header("Location:?admin=smiles&".passgen());
exit;
}
elseif(isset($_GET['edit']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_smiles` WHERE `id` = '".intval($_GET['edit'])."'"),0)!=0 && $ku['status']==3)
{
$smile=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_smiles` WHERE `id` = '".intval($_GET['edit'])."'"));
if(isset($_POST['submited']) && isset($_POST['name']))
{
$name=$_POST['name'];
$name=str_replace(' ','',$name);
$q=explode(',',$name);
$count=0;
$name=NULL;
foreach($q as $key => $value)
{
if($value!=NULL){$name=($name!=NULL?$name.",":null)."$value";$count++;}
}
if($count==0)err_game("Введите хоть одно название.");
else
{
mysql_query("UPDATE `kolhoz_smiles` SET `name` = '$name' WHERE `id` = '$smile[id]'");
header("Location: ?admin=smiles");
exit;
}
}
?>
<div class="event">
<h1>Редактировать</h1>
</div>
<div class="content">
<ul class="blockings">
<?
echo "<form method='post'>";
echo "Названия (через запитую):<br/>";
echo "<input type='text' name='name' value='".hsc($smile['name'])."'><br/>";
echo "<input type='submit' name='submited' value='Сохранить'><br/>";
echo "</form></ul>";
include_once 'inc/foot.php';
}
?>
<div class="event">
<h1>Смайлы</h1>
</div>
<div class="content">
<ul class="blockings">
<?
$q=mysql_query("SELECT * FROM `kolhoz_smiles` ORDER BY `id` ASC");
while($post=mysql_fetch_array($q))
{
$n=explode(',',$post['name']);
$nn=NULL;
foreach($n as $key => $value)
{
$nn=($nn!=NULL?$nn." или ":null)."$value";
}

$post['name']=$nn;
echo "<li><img src='img/smiles/$post[img]' alt='o'> ".($ku['status']==3?"<a href=?admin=smiles&edit=$post[id]'>":null)."".hsc($post['name'])."".($ku['status']==3?"</a>":null).''.($ku['status']==3?" <a href='?admin=smiles&delete=$post[id]'>[удалить]</a>":null)."</li>";
}
if($ku['status']==3)
echo "<li>&raquo; <a href='?admin=smiles&add'>Добавить смайл</a></li>";
echo "</ul>";
include_once 'inc/foot.php';
?>