<?
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']))
{
$type=$_POST['type'];
if(strlen2($type)<1){$err=1;err_game('Неправильный тип госзаказа');}
$id=intval($_POST['id']);
$id_plant=intval($_POST['id_plant']);
$active=intval($_POST['active']);
if(!is_numeric($id) || strlen2($id)<1){$err=1;err_game('Неверный id');}
if(!is_numeric($id_plant) || strlen2($id_plant)<1){$err=1;err_game('Неверный id растения');}
if(!is_numeric($active) || strlen2($active)<1){$err=1;err_game('Неверный действующий гос');}
if (!isset($err))
{
mysql_query("INSERT INTO `kolhoz_collective_gos` SET `id` = '$id', `time` = '$time', `id_plant` = '$id_plant', `type` = '".mysql_real_escape_string($type)."', `active` = '$active'");
header("location: ?admin=$admin");
}
}
echo "<form method=\"post\">\n";
echo "id госзаказа:<br /><input name=\"id\" type=\"text\" maxlength='32' value='' /><br />\n";echo "id растения:<br /><input name=\"id_plant\" type=\"text\" maxlength='32' value='' /><br />\n";echo "Тип госзаказа (rating или harvest):<br /><input name=\"type\" type=\"text\" maxlength='32' value='' /><br />\n";echo "Активность (0 или 1):<br /><input name=\"active\" 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 `kolhoz_collective_gos` WHERE `id` = '".intval($_GET['edit'])."'"),0)!=0)
{
echo "<div class='event'><h1><a href='?admin=$admin'>$admin_name</a> / Редактировать</h1></div>";
echo '<div class="content"><div class="block">';
$edit=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_collective_gos` WHERE `id` = '".intval($_GET['edit'])."'"));
if(isset($_POST['ok']))
{
$type=$_POST['type'];
if(strlen2($type)<1){$err=1;err_game('Неправильный тип госзаказа');}
$id=intval($_POST['id']);
$time=intval($_POST['time']);
$id_plant=intval($_POST['id_plant']);
$active=intval($_POST['active']);
if(!is_numeric($id) || strlen2($id)<1){$err=1;err_game('Неверный id');}
if(!is_numeric($time) || strlen2($time)<1){$err=1;err_game('Неверное к-тво времени');}
if(!is_numeric($id_plant) || strlen2($id_plant)<1){$err=1;err_game('Неверный id растения');}
if(!is_numeric($active) || strlen2($active)<1){$err=1;err_game('Неверный действующий гос');}
if (!isset($err))
{
mysql_query("UPDATE `kolhoz_collective_gos` SET `id` = '$id', `time` = '$time', `id_plant` = '$id_plant', `active` = '$active', `type` = '".mysql_real_escape_string($type)."' WHERE `id` = '$edit[id]'");
header("Location:?admin=$admin");
}
}
echo "<form method=\"post\">\n";
echo "Номер госзаказа:<br /><input name=\"id\" type=\"text\" maxlength='32' value='$edit[id]' /><br />\n";echo "Время до окончания:<br /><input name=\"time\" type=\"text\" maxlength='32' value='$edit[time]'/><br />\n";echo "id растения:<br /><input name=\"id_plant\" type=\"text\" maxlength='32' value='$edit[id_plant]'/><br />\n";echo "Тип госзаказа (rating или harvest):<br /><input name=\"type\" type=\"text\" maxlength='32' value='$edit[type]'/><br />\n";echo "Активность (0 или 1):<br /><input name=\"active\" type=\"text\" maxlength='32' value='$edit[active]' /><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']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_collective_gos` WHERE `id` = '".intval($_GET['del'])."'"),0)!=0)
{
$del=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_collective_gos` WHERE `id` = '".intval($_GET['del'])."'"));
if(isset($_GET['ok']))
{
mysql_query("DELETE FROM `kolhoz_collective_gos` WHERE `id` = '$del[id]'");
header("Location:?admin=$admin");
}
podtv("?admin=$admin&del=$del[id]&ok","?admin=$admin");
echo "</div>";
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 `kolhoz_collective_gos`"),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 `kolhoz_collective_gos` ORDER BY `id` DESC LIMIT $start, $set[p_str]");
while($post=mysql_fetch_array($q))
{
echo "<li><a href='?admin=$admin&edit=$post[id]'><span>$post[id] госзаказ</span></a> (<img width='16' height='16' src='images/icons/seat.png' alt='o'> <span>$post[id_plant]</span> <img width='16' height='16' src='images/icons/trophy.png' alt='o'>
<span>".rating($post['active'])."</span>)</li>";
}
if ($k_page>1)str("?admin=$admin&",$k_page,$page); // Вывод страниц
echo "<div><a href='?admin=$admin&add'>Создать госзаказ</a></div>";
echo "</ul></div>";
include_once 'inc/foot.php';
exit;
?>