Файл: vsime.com/moderate_dir/inc/act_main_menu.php
Строк: 246
<?
$title .= ' - Главное меню';
if (isset($_GET['moderate']))
{
if ($_GET['moderate'] == 'add')
{
$title .= ' - Добавить пункт';
ex_head();
if (isset($_POST['submited']))
{
$name = $_POST['name'];
$link = $_POST['link'];
$type = $_POST['type'];
$counter = $_POST['counter'];
$icon = $_POST['icon'];
if ($type == 'link')
{
if ($name == NULL)$error[] = 'Введите название.';
if ($link == NULL)$error[] = 'Введите ссылку.';
}
if (!isset($error))
{
$pos = mysqli_result("SELECT MAX(`pos`) FROM `main_menu`") + 1;
mysqli_query($dbi, "INSERT INTO `main_menu` SET `type` = '$type'".(($type == 'link')?", `name` = '$name', `link` = '$link', `counter` = '$counter', `icon` = '$icon'":NULL).", `pos` = '$pos'");
header("Location: ?act=main_menu");
exit();
}
}
show_errors();
echo "<form method='POST'>n";
echo "Тип:<br />n";
echo "<select name='type'>n";
echo "<option value='link'>Ссылка</option>n";
echo "<option value='cat'>Разделитель</option>n";
echo "</select><br />n";
echo "Название:<br />n";
echo "<input type='text' name='name' /><br />n";
echo "Ссылка:<br />n";
echo "<input type='text' name='link' /><br />n";
echo "Счетчик:<br />n";
echo "<input type='text' name='counter' /><br />n";
echo "Иконка:<br />n";
echo "<input type='text' name='icon' /><br />n";
echo "<input type='submit' name='submited' value='Добавить' /> <a href='?act=main_menu'>Отмена</a>n";
echo "</form>n";
ex_foot();
}
if ($_GET['moderate'] == 'edit')
{
$edit = mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `main_menu` WHERE `id` = '".intval($_GET['id'])."'"));
if ($edit == NULL)
{
$title .= ' - Ошибка!';
ex_head();
$error[] = 'Обьект не найден.';
show_errors();
ex_foot();
}
$title .= ' - Редактировать пункт';
ex_head();
if (isset($_POST['submited']))
{
$name = $_POST['name'];
$link = $_POST['link'];
$type = $_POST['type'];
$counter = $_POST['counter'];
$icon = $_POST['icon'];
if ($type == 'link')
{
if ($name == NULL)$error[] = 'Введите название.';
if ($link == NULL)$error[] = 'Введите ссылку.';
}
if (!isset($error))
{
mysqli_query($dbi, "UPDATE `main_menu` SET `type` = '$type'".($type == 'link'?", `name` = '$name', `link` = '$link', `counter` = '$counter', `icon` = '$icon'":NULL)." WHERE `id` = '$edit[id]'");
header("Location: ?act=main_menu");
exit();
}
}
show_errors();
echo "<form method='POST'>n";
echo "Тип:<br />n";
echo "<select name='type'>n";
echo "<option value='link'".($edit['type']=='link'?" selected='selected'":NULL).">Ссылка</option>n";
echo "<option value='cat'".($edit['type']=='cat'?" selected='selected'":NULL).">Разделитель</option>n";
echo "</select><br />n";
echo "Название:<br />n";
echo "<input type='text' name='name' value='".input_value($edit['name'])."' /><br />n";
echo "Ссылка:<br />n";
echo "<input type='text' name='link' value='".input_value($edit['link'])."' /><br />n";
echo "Иконка:<br />n";
echo "<input type='text' name='icon' value='".input_value($edit['icon'])."' /><br />n";
echo "Счетчик:<br />n";
echo "<input type='text' name='counter' value='".input_value($edit['counter'])."' /><br />n";
echo "<input type='submit' name='submited' value='Сохранить' /> <a href='?act=main_menu'>Отмена</a>n";
echo "</form>n";
ex_foot();
}
if ($_GET['moderate'] == 'delete')
{
$delete = mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `main_menu` WHERE `id` = '".intval($_GET['id'])."'"));
if ($delete == NULL)
{
$title .= ' - Ошибка!';
ex_head();
$error[] = 'Обьект не найден.';
show_errors();
ex_foot();
}
$title .= ' - Удалить пункт';
ex_head();
if (isset($_POST['submited']))
{
$queryuery = mysqli_query($dbi, "SELECT * FROM `main_menu` WHERE `pos` > '$delete[pos]' ORDER BY `pos` ASC");
while ($post = mysqli_fetch_array($queryuery))
{
mysqli_query($dbi, "UPDATE `main_menu` SET `pos` = '".($post['pos']-1)."' WHERE `id` = '$post[id]' LIMIT 1");
}
mysqli_query($dbi, "DELETE FROM `main_menu` WHERE `id` = '$delete[id]'");
header("Location: ?act=main_menu");
exit();
}
echo "<form method='POST'>n";
echo "Подтвердите удаление пункта<br />n";
echo "<input type='submit' name='submited' value='Удалить' /> <a href='?act=main_menu'>Отмена</a>n";
echo "</form>n";
ex_foot();
}
if ($_GET['moderate'] == 'up')
{
$up = mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `main_menu` WHERE `id` = '".intval($_GET['id'])."' LIMIT 1"));
if ($up == NULL)
{
$title .= ' - Ошибка!';
ex_head();
$error[] = 'Обьект не найден.';
show_errors();
ex_foot();
}
if(mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `main_menu` WHERE `pos` < '$up[pos]' LIMIT 1"))!=0)
{
mysqli_query($dbi, "UPDATE `main_menu` SET `pos` = '".($up['pos'])."' WHERE `pos` = '".($up['pos']-1)."' LIMIT 1");
mysqli_query($dbi, "UPDATE `main_menu` SET `pos` = '".($up['pos']-1)."' WHERE `id` = '$up[id]' LIMIT 1");
}
}
if ($_GET['moderate'] == 'down')
{
$up = mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `main_menu` WHERE `id` = '".intval($_GET['id'])."' LIMIT 1"));
if ($up == NULL)
{
$title .= ' - Ошибка!';
ex_head();
$error[] = 'Обьект не найден.';
show_errors();
ex_foot();
}
$down = mysqli_fetch_array(mysqli_query($dbi, "SELECT * FROM `main_menu` WHERE `id` = '".intval($_GET['id'])."' LIMIT 1"));
if(mysqli_num_rows(mysqli_query($dbi, "SELECT * FROM `main_menu` WHERE `pos` > '$down[pos]' LIMIT 1"))!=0)
{
mysqli_query($dbi, "UPDATE `main_menu` SET `pos` = '".($down['pos'])."' WHERE `pos` = '".($down['pos']+1)."' LIMIT 1");
mysqli_query($dbi, "UPDATE `main_menu` SET `pos` = '".($down['pos']+1)."' WHERE `id` = '$down[id]' LIMIT 1");
}
}
}
ex_head();
$queryuery = mysqli_query($dbi, "SELECT * FROM `main_menu` ORDER BY `pos` ASC");
if (!mysqli_num_rows($queryuery))
{
echo "<div class='list'>n";
echo "Список пустn";
echo "</div>n";
}
while ($post = mysqli_fetch_array($queryuery))
{
echo " <div class='list'>n";
echo "<span class='right'>n";
echo "<a href='?act=main_menu&moderate=up&id=$post[id]'>$config[code_up]</a> <a href='?act=main_menu&moderate=down&id=$post[id]'>$config[code_down]</a> <a href='?act=main_menu&moderate=edit&id=$post[id]'>$config[code_edit]</a> <a href='?act=main_menu&moderate=delete&id=$post[id]'>$config[code_delete]</a>n";
echo "</span>n";
if ($post['type']=='link')
{
echo main_menu_icon($post['icon']);
echo " $post[pos]) $post[name] ($post[link])n";
echo "<br />n";
echo "Счетчик: ".($post['counter']==null?'отсутствует':(!is_file(H.$post['counter'])?"<span class='spared'>":"<span class='spagr'>")."$post[counter]</span>")."<br />n";
} else {
echo main_menu_icon($post['icon']);
echo " $post[pos]) Разделn";
}
echo "</div>n";
}
echo "<div class='foot'>n";
echo "$config[code_add] <a href='?act=main_menu&moderate=add'>Добавить пункт</a>n";
echo "</div>n";
ex_foot();
?>