Файл: adm_panel/menu.php
Строк: 269
<?php
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/adm_check.php';
include_once '../sys/inc/user.php';
include_once '../sys/inc/icons.php'; // Иконки главного меню
user_access('adm_menu', null, 'index.php?' . SID);
adm_check();
$set['title'] = 'Главное меню';
include_once '../sys/inc/thead.php';
title();
$opendiricon = opendir(H . 'style/icons');
while ($icons = readdir($opendiricon)) {
// запись всех тем в массив
if (preg_match('#^.|default.png#', $icons))
continue;
$icon[] = $icons;
}
closedir($opendiricon);
aut();
err();
if (isset($_POST['add']) && isset($_POST['name']) && $_POST['name'] != NULL) {
$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;
$type = my_esc($_POST['type']);
$icon = preg_replace('#[^a-z0-9 _-.]#i', null, $_POST['icon']);
mysql_query("INSERT INTO `menu` (`name`, `url`, `counter`, `pos`, `icon`, `type`) VALUES ('$name', '$url', '$counter', '$pos', '$icon', '$type')");
msg('Ссылка успешно добавлена');
}
if (isset($_POST['change']) && isset($_GET['id']) && isset($_POST['name']) && $_POST['name'] != NULL && isset($_POST['url'])) {
$id = intval($_GET['id']);
$name = esc(stripcslashes(htmlspecialchars($_POST['name'])));
$url = esc(stripcslashes(htmlspecialchars($_POST['url'])));
if (isset($_POST['counter']))
$counter = esc(stripcslashes(htmlspecialchars($_POST['counter'])));
else
$counter = null;
$icon = preg_replace('#[^a-z0-9 _-.]#i', null, $_POST['icon']);
mysql_query("UPDATE `menu` SET `name` = '$name', `url` = '$url', `counter` = '$counter', `icon` = '$icon' WHERE `id` = '$id' LIMIT 1");
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_assoc(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");
mysql_query("UPDATE `menu` SET `pos` = ( SELECT @var := @var +1 FROM (SELECT @var :=0) AS tbl ) ;");
msg('Пункт меню удален');
}
}
$q = mysql_query("SELECT * FROM `menu` ORDER BY `pos` ASC");
while ($post = mysql_fetch_assoc($q)) {
if (isset($_GET['id']) && $_GET['id'] == $post['id'] && isset($_GET['act']) && $_GET['act'] == 'edit') {
echo "<div class='list-group-item'>";
if (!isset($post['icon'])) {
mysql_query('ALTER TABLE `menu` ADD `icon` VARCHAR( 32 ) NULL DEFAULT NULL');
}
if (!isset($post['type'])) {
mysql_query("ALTER TABLE `menu` ADD `type` ENUM('link', 'razd', 'inc') NOT NULL DEFAULT 'link' AFTER `id`");
}
if ($post['type'] == 'link') {
echo icons($post['icon'], 'code');
}
echo "<div style = 'float:right;color:grey;'>$post[pos]</div>";
echo "$post[pos]. $post[name] " . ($post['type'] == 'link' ? "($post[url])" : null);
echo "</div>";
echo "<form class='list-group-item' action = '?id=$post[id]' method = 'post'>";
if ($post['type'] != 'inc') {
echo "Тип: " . ($post['type'] == 'link' ? 'Ссылка' : 'Разделитель') . "<br />";
}
echo "<input class='form-control' placeholder = 'Название' type = 'text' name = 'name' value = '$post[name]' /><br />";
if ($post['type'] == 'link' or $post['type'] == 'inc') {
echo "<input class='form-control' placeholder = 'Ссылка' type = 'text' name = 'url' value = '$post[url]' /><br />";
} else {
echo "<input class='form-control' placeholder = 'Ссылка' type = 'hidden' name = 'url' value = '' />";
}
if ($post['type'] != 'inc') {
echo "<input class='form-control' placeholder = 'Счетчик' type = 'text' name = 'counter' value = '$post[counter]' /><br />";
}
if ($post['type'] == 'link') {
echo '<input type="text" class="form-control" name="icon" value = "' . $post['icon'] . '" />';
} else {
echo "<input type = 'hidden' name = 'icon' value = '$post[icon]' />";
}
echo "<br />";
echo "<button name='change' class='btn btn-success'><span class='fa fa-save'></span> Сохранить</button> ";
echo "<a class='btn btn-secondary' href='?$passgen'>Отмена</a>";
echo "</form>";
} else {
echo "<div class='list-group-item'>";
if (!isset($post['icon'])) {
mysql_query('ALTER TABLE `umenu` ADD `icon` VARCHAR( 32 ) NULL DEFAULT NULL');
}
if (!isset($post['type'])) {
mysql_query("ALTER TABLE `umenu` ADD `type` ENUM('link') NOT NULL DEFAULT 'link' AFTER `id`");
}
echo "<div style = 'float:right;color:grey;'>";
echo "<a href = '?id=$post[id]&act=up&$passgen' title = 'Выше'><span class='fa fa-arrow-up'></span></a> ";
echo "<a href = '?id=$post[id]&act=down&$passgen' title = 'Ниже'><span class='fa fa-arrow-down'></span></a>";
echo "</div>";
//echo "$post[pos] ";
if ($post['type'] == 'link') {
echo icons($post['icon']);
}
echo " $post[name]<br />";
echo "<small>Файл: " . ($post['type'] == 'link' ? "$post[url]" : null) . "</small><br />";
echo "<span style='float:right;color:grey;'>";
echo "<a href='?id=$post[id]&act=edit&$passgen' title='Редактировать'><span class='fa fa-pencil-square-o'></span></a> ";
echo "<a href='?id=$post[id]&act=del&$passgen' title='Удалить'><span class='fa fa-trash-o'></span></a>";
echo "</span>";
if ($post['type'] != 'inc') {
echo "<small>Счетчик: " . ($post['counter'] == null ? 'отсутствует' : $post['counter']) . "</small>n";
} else {
echo "<small>Инклуд: " . output_text($post['url']) . "</small>";
}
echo "</div>";
}
}
if (isset($_GET['add'])) {
echo "<form action='?add=$passgen' class='list-group-item' method='post'>";
echo "<select name='type' class='form-control'>";
echo "<option value='link'>Ссылка (1)</option>";
echo "<option value='razd'>Раздел (2)</option>";
echo "<option value='inc'>Инклуд (3)</option>";
echo "</select><br />";
echo "<input class='form-control' placeholder='Название' type='text' name='name' value='' /><br />";
echo "<input class='form-control' placeholder='Ссылка' type='text' name='url' value='' /><br />";
echo "<input class='form-control' placeholder='Счетчик' type='text' name='counter' value='' /><br />";
echo "<input class='form-control' placeholder='Иконка fa fa-' type='text' name='icon' value='' />";
echo "Иконки - <a href='https://fortawesome.github.io/Font-Awesome/icons/'>https://fortawesome.github.io/Font-Awesome/icons/</a><br />";
echo "<button name='add' class='btn btn-success'><span class='fa fa-plus'></span> Добавить</button> ";
echo "<a class='btn btn-secondary' href='?$passgen'>Отмена</a>";
echo "</form>";
} else {
echo "<form action='?add=$passgen' class='list-group-item' method='post'>";
echo "<button class='btn btn-success'><span class='fa fa-plus'></span> Добавить пункт</button>";
echo "</form>";
}
echo "<div class='list-group-item'><a href='/adm_panel/'><span class='fa fa-arrow-left'></span> Панель управления</a></div>";
include_once '../sys/inc/tfoot.php';