<?
if(isset($_GET['addplant']) && intval($_GET['addplant'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_plant` WHERE `id` = '".intval($_GET['addplant'])."'"),0)!=0)
{
echo "<div class='event'><h1><a href='?admin=$admin'>$admin_name</a> / Добавить</h1></div>";
echo '<div class="content"><div class="block">';
$plant=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant` WHERE `id` = '".intval($_GET['addplant'])."'"));
if(isset($_POST['ok']))
{
$priz=intval($_POST['priz']);
$count=intval($_POST['count']);
$level=intval($_POST['level']);
$id_plant=intval($_GET['addplant']);
if(!is_numeric($level) || strlen2($level)<1){$err=1;err_game('Неверный уровень доступности');}
if(!is_numeric($priz) || strlen2($priz)<1){$err=1;err_game('Неверная прибыль');}
if (!isset($err))
{

mysql_query("INSERT INTO `zadaniy` SET `id_plant` = '$id_plant', `priz` = '$priz', `count` = '$count', `level` = '$level'");
header("location: ?admin=$admin");
}
}

echo "<h3>Вы добавляете растение</h3>";

echo "<li style='padding-bottom:8px'>";
echo "<img width='48' height='48' src='images/plants/$plant[id].png' alt='o' class='portrait'>";
echo "<div class='small'>";
echo "<span><a href='?admin=plants&edit=$plant[id]'>".hsc($plant['name'])."</a></span> <span class='title'>(id$plant[id])</span> <span class='minor'>, цена: </span><span><img width='16' height='16' src='images/icons/money.png' alt='o'><span class='title'>$plant[cena]</span></span> (доступно с $plant[level] уровня</span>)</div><div class='small minor'> Время созревания: <span class='title'>".time_left($plant['time'])."</span>, Время до удобрения: <span class='title'>".time_left($plant['time_soil'])."</span><br>Доход: <img width='16' height='16' src='images/icons/money.png' alt='o'> <span>$plant[money]</span>,
Опыт: <img width='16' height='16' src='images/icons/experience.png' alt='o'> <span>$plant[rating]</span>,
Урожай: <span>$plant[count]</span> <span>шт.</span></div></li>";
echo "<h3>Параметры</h3>";
echo "<form method=\"post\" enctype='multipart/form-data'>\n";
echo "Прибыль:<br /><input name=\"priz\" type=\"text\" maxlength='32' value='' /><br />\n";
echo "К-тво урожая для сбора:<br /><input name=\"count\" type=\"text\" maxlength='32' value=''/><br />\n";
echo "Уровень доступности:<br /><input name=\"level\" type=\"text\" maxlength='32' value='$plant[level]'/><br />\n";
echo "<input value='Добавить' type='submit' name='ok' /><br />\n";
echo "</form>\n";
echo "</div>";
include_once 'inc/foot.php';
exit;
}






if(isset($_GET['add']))
{
echo "<div class='event'><h1><a href='?admin=$admin'>$admin_name</a> / Добавить</h1></div>";
echo '<div class="content"><div class="block">';
if(isset($_POST['ok']))
{
$priz=intval($_POST['priz']);
$count=intval($_POST['count']);
$level=intval($_POST['level']);
$id_plant=intval($_POST['id_plant']);
if(!is_numeric($level) || strlen2($level)<1){$err=1;err_game('Неверный уровень доступности');}
if(!is_numeric($priz) || strlen2($priz)<1){$err=1;err_game('Неверная прибыль');}
if (!isset($err))
{

mysql_query("INSERT INTO `zadaniy` SET `id_plant` = '$id_plant', `priz` = '$priz', `count` = '$count', `level` = '$level'");
header("location: ?admin=$admin");
}
}
echo "<form method=\"post\" enctype='multipart/form-data'>\n";
echo "ID растения:<br /><input name=\"id_plant\" type=\"text\" maxlength='32' value='' /><br />\n";
echo "Прибыль:<br /><input name=\"priz\" type=\"text\" maxlength='32' value='' /><br />\n";
echo "К-тво урожая для сбора:<br /><input name=\"count\" type=\"text\" maxlength='32' value=''/><br />\n";
echo "Уровень доступности:<br /><input name=\"level\" type=\"text\" maxlength='32' value=''/><br />\n";
echo "<input value='Добавить' type='submit' name='ok' /><br />\n";
echo "</form>\n";
echo "</div>";
include_once 'inc/foot.php';
exit;
}





if(isset($_GET['edit']) && intval($_GET['edit'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `zadaniy` WHERE `id` = '".intval($_GET['edit'])."'"),0)!=0)
{
$edit=mysql_fetch_array(mysql_query("SELECT * FROM `zadaniy` WHERE `id` = '".intval($_GET['edit'])."'"));


echo "<div class='event'><h1><a href='?admin=$admin'>$admin_name</a> / Редактировать</h1></div>";
echo '<div class="content"><div class="block">';
$plant=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant` WHERE `id` = '$edit[id_plant]'"));
if(isset($_POST['ok']))
{
$priz=intval($_POST['priz']);
$count=intval($_POST['count']);
$level=intval($_POST['level']);
$id_plant=intval($_POST['id_plant']);
if(!is_numeric($level) || strlen2($level)<1){$err=1;err_game('Неверный уровень доступности');}
if(!is_numeric($priz) || strlen2($priz)<1){$err=1;err_game('Неверная прибыль');}
if (!isset($err))
{
mysql_query("UPDATE `zadaniy` SET `priz` = '$priz', `count` = '$count', `id_plant` = '$id_plant', `level` = '$level' WHERE `id` = '$edit[id]'");
header("Location:?admin=$admin");
}
}
echo "<h3>Растение</h3>";

echo "<li style='padding-bottom:8px'>";
echo "<img width='48' height='48' src='images/plants/$plant[id].png' alt='o' class='portrait'>";
echo "<div class='small'>";
echo "<span><a href='?admin=plants&edit=$plant[id]'>".hsc($plant['name'])."</a></span> <span class='title'>(id$plant[id])</span> <span class='minor'>, цена: </span><span><img width='16' height='16' src='images/icons/money.png' alt='o'><span class='title'>$plant[cena]</span></span> (доступно с $plant[level] уровня</span>)</div><div class='small minor'> Время созревания: <span class='title'>".time_left($plant['time'])."</span>, Время до удобрения: <span class='title'>".time_left($plant['time_soil'])."</span><br>Доход: <img width='16' height='16' src='images/icons/money.png' alt='o'> <span>$plant[money]</span>,
Опыт: <img width='16' height='16' src='images/icons/experience.png' alt='o'> <span>$plant[rating]</span>,
Урожай: <span>$plant[count]</span> <span>шт.</span></div></li>";
echo "<h3>Параметры</h3>";
echo "<div style='clear:both'></div>";
echo "<form method=\"post\" enctype='multipart/form-data'>\n";
echo "ID растения:<br /><input name=\"id_plant\" type=\"text\" maxlength='32' value='$edit[id_plant]' /><br />\n";
echo "Прибыль:<br /><input name=\"priz\" type=\"text\" maxlength='32' value='$edit[priz]' /><br />\n";
echo "К-тво урожая для сбора:<br /><input name=\"count\" type=\"text\" maxlength='32' value='$edit[count]'/><br />\n";
echo "Уровень доступности:<br /><input name=\"level\" type=\"text\" maxlength='32' value='$edit[level]'/><br />\n";
echo "<input value='Сохранить' type='submit' name='ok' /></form>\n";
echo "<div><br/>&raquo; <a href='?admin=$admin&del=$edit[id]'>Удалить</a></div>";
echo "</div>";
include_once 'inc/foot.php';
exit;
}



if(isset($_GET['del']) && intval($_GET['del'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `zadaniy` WHERE `id` = '".intval($_GET['del'])."'"),0)!=0)
{
$del=mysql_fetch_array(mysql_query("SELECT * FROM `zadaniy` WHERE `id` = '".intval($_GET['del'])."'"));
if(isset($_GET['ok']))
{
mysql_query("DELETE FROM `zadaniy` WHERE `id` = '$del[id]'");
header("Location:?admin=$admin");
}
podtv("?admin=$admin&del=$del[id]&ok","?admin=$admin");
include_once 'inc/foot.php';
exit;
}

echo "<div class='event'><h1><a href='?admin=list'>Админка</a> / $admin_name</h1></div>";
echo '<div class="content"><div class="block">';


$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `zadaniy`"),0);
if ($k_post==0)
{
echo "Список пуст...";
}
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];
$q=mysql_query("SELECT * FROM `zadaniy` ORDER BY `id` DESC LIMIT $start, $set[p_str]");
while($post=mysql_fetch_array($q))
{
$plant=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant` WHERE `id` = '$post[id_plant]'"));
echo "<li style='padding-bottom:8px'>";
echo "<img width='48' height='48' src='images/plants/$post[id_plant].png' alt='o' class='portrait'>";
echo "<div class='small'>";
echo "<span><a href='?admin=$admin&edit=$post[id]'>".hsc($plant['name'])."</a></span> <span class='title'>(id$post[id])</span>  <span class='minor'><br>Прибыль: </span><span><img width='16' height='16' src='images/icons/ruby.png' alt='o'><span class='title'>$post[priz]</span></span><br><span class='minor'>Уровень: $post[level]</span><br><span class='minor'>Нужно:</span> <span class='title'>$post[count]</span></div></li>";
}
echo "</ul>";
if ($k_page>1)str("?admin=$admin&",$k_page,$page); // Вывод страниц
echo "<div>&raquo; <a href='?admin=$admin&add'>Добавить растение</a></div>";
echo "</div>";
include_once 'inc/foot.php';
?>