<?
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';
only_level(4);
$set['title']='Главное меню';
include_once '../sys/inc/thead.php';
title();
if (!isset($access['main_menu_edit'])){header("Location: index.php?".SID);exit;}
if (isset($_POST['name']) && $_POST['name']!=NULL && isset($_POST['url']) && $_POST['url']!=NULL && isset($_POST['counter']))
{
$name=esc(stripcslashes(htmlspecialchars($_POST['name'])));
$url=esc(stripcslashes(htmlspecialchars($_POST['url'])));
$counter=esc(stripcslashes(htmlspecialchars($_POST['counter'])));
$pos=mysql_result(mysql_query("SELECT MAX(`pos`) FROM `menu`"), 0)+1;

mysql_query("INSERT INTO `menu` (`name`, `url`, `counter`, `pos`) VALUES ('$name', '$url', '$counter', '$pos')");
msg('Ссылка успещно добавлена');
}


if (isset($_GET['id']) && isset($_GET['act']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `menu` WHERE `id` = '".intval($_GET['id'])."'"),0))
{

$menu=mysql_fetch_array(mysql_query("SELECT * FROM `menu` WHERE `id` = '".intval($_GET['id'])."' LIMIT 1"));
if ($_GET['act']=='up')
{
mysql_query("UPDATE `menu` SET `pos` = '".($menu['pos'])."' WHERE `pos` = '".($menu['pos']-1)."' LIMIT 1");
mysql_query("UPDATE `menu` SET `pos` = '".($menu['pos']-1)."' WHERE `id` = '".intval($_GET['id'])."' LIMIT 1");

msg('Пункт меню сдвинут на позицию вверх');
}
if ($_GET['act']=='down')
{
mysql_query("UPDATE `menu` SET `pos` = '".($menu['pos'])."' WHERE `pos` = '".($menu['pos']+1)."' LIMIT 1");
mysql_query("UPDATE `menu` SET `pos` = '".($menu['pos']+1)."' WHERE `id` = '".intval($_GET['id'])."' LIMIT 1");

msg('Пункт меню сдвинут на позицию вниз');
}
if ($_GET['act']=='del')
{

mysql_query("DELETE FROM `menu` WHERE `id` = '".intval($_GET['id'])."' LIMIT 1");

msg('Пункт меню удален');
}


}



err();
aut();
echo "<table class='post'>\n";

$q=mysql_query("SELECT * FROM `menu` ORDER BY `pos` ASC");
while ($post = mysql_fetch_array($q))
{
echo "   <tr>\n";

echo "  <td class='p_t'>\n";
echo "$post[pos]) $post[name] ($post[url])";
echo "  </td>\n";
echo "   </tr>\n";
echo "   <tr>\n";
echo "  <td class='p_m'>\n";
echo "Счетчик: $post[counter]<br />\n";
echo "<a href='?id=$post[id]&amp;act=up'>Выше</a> | ";
echo "<a href='?id=$post[id]&amp;act=down'>Ниже</a> | ";
echo "<a href='?id=$post[id]&amp;act=del'>Удалить </a>";
echo "  </td>\n";
echo "   </tr>\n";
}


echo "</table>\n";
echo "<form class=\"foot\" action=\"?\" method=\"post\">";
echo "Название:<br />\n";
echo "<input type=\"text\" name=\"name\" value=\"\"/><br />\n";
echo "Ссылка:<br />\n";
echo "<input type=\"text\" name=\"url\" value=\"\"/><br />\n";
echo "Счетчик:<br />\n";
echo "<input type=\"text\" name=\"counter\" value=\"\"/><br />\n";
echo "<input class=\"submit\" type=\"submit\" value=\"Добавить\" /><br />\n";
echo "</form>";


echo "<div class='foot'>\n";
echo "&laquo;<a href='/adm_panel/'>В админку</a><br />\n";
echo "</div>\n";
include_once '../sys/inc/tfoot.php';
?>