Файл: panel/adm_menu.php
Строк: 208
<?php
/* DCMS Special
* Дата последнего редактирования 15.12.2015
* Модифицировал densnet
*/
foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'adm_check', 'user') as $inc) {
require_once "../sys/inc/{$inc}.php";
}
access('adm_menu', null, 'index.php?' . SID);
adm_check();
$set['title'] = 'Меню';
require_once H . 'sys/inc/thead.php';
aut();
err();
#Навигация
echo "<ol class='breadcrumb'>";
echo "<li><a href='/'><span class='fa fa-home fa-fw'></span></a></li>";
echo "<li><a href='/panel/'>Панель управления</a></li>";
echo "<li class='active'>Редактор панели управления</li>";
echo "</ol>";
if (isset($_POST['add']) && 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 `adm_menu`"), 0) + 1;
$icon = preg_replace('#[^a-z0-9 _-.]#i', null, $_POST['icon']);
mysql_query("INSERT INTO `adm_menu` (`name`, `url`, `counter`, `pos`, `icon`) VALUES ('$name', '$url', '$counter', '$pos', '$icon')");
msg('Ссылка успешно добавлена');
header("Refresh: 1; url=?");
}
if (isset($_POST['change']) && isset($_GET['id']) && isset($_POST['name']) && $_POST['name'] != NULL && isset($_POST['url']) && isset($_POST['counter'])) {
$id = intval($_GET['id']);
$name = esc(stripcslashes(htmlspecialchars($_POST['name'])));
$url = esc(stripcslashes(htmlspecialchars($_POST['url'])));
$counter = esc(stripcslashes(htmlspecialchars($_POST['counter'])));
$icon = preg_replace('#[^a-z0-9 _-.]#i', null, $_POST['icon']);
mysql_query("UPDATE `adm_menu` SET `name` = '$name', `url` = '$url', `counter` = '$counter', `icon` = '$icon' WHERE `id` = '$id' LIMIT 1");
msg('Пункт меню успешно изменен');
header("Refresh: 1; url=?");
}
if (isset($_GET['id']) && isset($_GET['act']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `adm_menu` WHERE `id` = '" . intval($_GET['id']) . "'"), 0)) {
$menu = mysql_fetch_assoc(mysql_query("SELECT * FROM `adm_menu` WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1"));
if ($_GET['act'] == 'up') {
mysql_query("UPDATE `adm_menu` SET `pos` = '" . ($menu['pos']) . "' WHERE `pos` = '" . ($menu['pos'] - 1) . "' LIMIT 1");
mysql_query("UPDATE `adm_menu` SET `pos` = '" . ($menu['pos'] - 1) . "' WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1");
msg('Пункт меню сдвинут на позицию вверх');
header("Refresh: 1; url=?");
}
if ($_GET['act'] == 'down') {
mysql_query("UPDATE `adm_menu` SET `pos` = '" . ($menu['pos']) . "' WHERE `pos` = '" . ($menu['pos'] + 1) . "' LIMIT 1");
mysql_query("UPDATE `adm_menu` SET `pos` = '" . ($menu['pos'] + 1) . "' WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1");
msg('Пункт меню сдвинут на позицию вниз');
header("Refresh: 1; url=?");
}
if ($_GET['act'] == 'del') {
mysql_query("DELETE FROM `adm_menu` WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1");
msg('Пункт меню удален');
header("Refresh: 1; url=?");
}
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `adm_menu`"), 0);
#Если нет разделов меню
if ($k_post == 0) {
echo "<div class='list-group-item'>";
echo "<i class='fa fa-info-circle fa-fw'></i> Нет результатов";
echo "</div>";
}
$q = mysql_query("SELECT * FROM `adm_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 `adm_menu` ADD `icon` VARCHAR( 32 ) NULL DEFAULT NULL');
}
if (!isset($post['type'])) {
mysql_query("ALTER TABLE `adm_menu` ADD `type` ENUM('link') 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'>";
echo "Тип: " . ($post['type'] == 'link' ? 'Ссылка' : '') . "<br />";
echo "<input class='form-control' placeholder = 'Название' type = 'text' name = 'name' value = '$post[name]' /><br />";
if ($post['type'] == 'link') {
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 = '' />";
}
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 "Иконки - <a href='https://fortawesome.github.io/Font-Awesome/icons/'>https://fortawesome.github.io/Font-Awesome/icons/</a><br />";
echo "<button name='change' class='btn btn-success'><i class='fa fa-save fa-fw'></i> Сохранить</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 `adm_menu` ADD `icon` VARCHAR( 32 ) NULL DEFAULT NULL');
}
if (!isset($post['type'])) {
mysql_query("ALTER TABLE `adm_menu` ADD `type` ENUM('link') NOT NULL DEFAULT 'link' AFTER `id`");
}
echo "<span style='float:right;color:grey;'>";
echo "<a href='?id=$post[id]&act=up&$passgen' title='Выше'><i class='fa fa-arrow-up fa-fw'></i></a> ";
echo "<a href='?id=$post[id]&act=down&$passgen' title='Ниже'><i class='fa fa-arrow-down fa-fw'></i></a>";
echo "</span>";
//echo "$post[pos] ";
if ($post['type'] == 'link') {
echo icons($post['icon']);
}
echo " $post[name]<br />";
echo "<span style='float:right;color:grey;'>";
echo "<a href='?id=$post[id]&act=edit&$passgen' title='Редактировать'><i class='fa fa-pencil-square-o fa-fw'></i></a> ";
echo "<a href='?id=$post[id]&act=del&$passgen' title='Удалить'><i class='fa fa-trash-o fa-fw'></i></a>";
echo "</span>";
echo "<font color='grey'><small>";
echo "Файл: " . ($post['type'] == 'link' ? "$post[url]" : null) . "</small><br />";
echo "Счетчик: " . ($post['counter'] == null ? 'отсутствует' : $post['counter']);
echo "</small></font>n";
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'>Ссылка *</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='fa fa-' />";
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'><i class='fa fa-plus fa-fw'></i> Добавить</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'><i class='fa fa-plus fa-fw'></i> Добавить пункт</button>";
echo "</form>";
}
require_once H . 'sys/inc/tfoot.php';