<?
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_spam` SET `name` = '$name', `img` = '$img'");
$tmp = $_FILES['file']['tmp_name'];
move_uploaded_file($tmp, 
"img/spam/$img");
chmod("img/spam/$img",0777);
header("Location: ?admin=spam");
exit;
}
}

if($ku['dostup']==1){echo "<div class='event'><h1>Добавить анти рекламный текст</h1></div><div class='content'>";
echo "<ul class='block'><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_spam` WHERE `id` = '".intval($_GET['delete'])."'"),0)!=0 && $ku['dostup']==1)
{
mysql_query("DELETE FROM `kolhoz_spam` WHERE `id` = '".intval($_GET['delete'])."'");
unlink("img/spam/".mysql_result(mysql_query("SELECT `img` FROM `kolhoz_spam` WHERE `id` = '".intval($_GET['delete'])."'"),0));
header("Location:?admin=spam&".passgen());
exit;
}
elseif(isset($_GET['edit']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_spam` WHERE `id` = '".intval($_GET['edit'])."'"),0)!=0 && $ku['dostup']==1)
{
$spam=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_spam` 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_spam` SET `name` = '$name' WHERE `id` = '$spam[id]'");
header("Location: ?admin=spam");
exit;
}
}

echo '<div class="event"><h1>Изменить анти рекламный текст</h1></div><div class="content"><ul class="block">';

echo "<form method='post'>";
echo "Доменные зоны или полный адрес игры (через запитую):<br/>";
//echo "<input type='text' name='name' value='".hsc($spam['name'])."'><br/>";
echo "<input rows='5' class='wide' name='name' value='".hsc($spam['name'])."'>";
echo "<input type='submit' name='submited' value='Сохранить'><br/>";
echo "</form></ul>";
include_once 'inc/foot.php';
}

echo '<div class="event"><h1>Анти реклама 2о14</h1></div><div class="content"><ul class="block">';
echo "<div class='block'> <a href='?admin=spam&add'>Добавить анти рекламный текст</a></div>";
//=====
if(isset($_GET['haps'])){
mysql_query("UPDATE `kolhoz_spam` SET `nadpis`='0'");
header("Location:?admin=spam");}
if(isset($_GET['hap'])){
mysql_query("UPDATE `kolhoz_spam` SET `nadpis`='1'");
header("Location:?admin=spam");}

$topcla = mysql_query("SELECT * FROM `kolhoz_spam` ORDER BY `id` DESC LIMIT 1") or die(mysql_error());
$spam = mysql_fetch_array($topcla);
echo "<div class='block'>На замене рекламы стоит: ";
if ($spam['nadpis']==1)echo "<font color='green'>Картинка</font> [<a href='?admin=spam&haps'>Изменить на текст</a>]";
if ($spam['nadpis']==0)echo "<font color='green'>Текст</font> [<a href='?admin=spam&hap'>Изменить на картинку</a>]";
echo "</div>";






//====
$q=mysql_query("SELECT * FROM `kolhoz_spam` 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 "<div class='block'><img src='img/spam/$post[img]' alt='o'> ".($ku['dostup']==1?"<a href='?admin=spam&edit=$post[id]'>":null)."".hsc($post['name'])."".($ku['dostup']==1?"</a>":null)."".($ku['dostup']==1?" [<a href='?admin=spam&delete=$post[id]'><b><font color='tomato'>Удалить</font></b></a>]":null)."</div>";
}
echo "</ul>";
include_once 'inc/foot.php';
?>