Файл: panel/umenu.php
Строк: 236
<?php
/* DCMS S (Special)
* Версия файла 0.0.1
* Дата последнего редактирования 25.11.2015
* Модифицировал densnet
*/
require_once '../sys/inc/start.php';
require_once H . 'sys/inc/compress.php';
require_once H . 'sys/inc/sess.php';
require_once H . 'sys/inc/settings.php';
require_once H . 'sys/inc/db_connect.php';
require_once H . 'sys/inc/ipua.php';
require_once H . 'sys/inc/fnc.php';
require_once H . 'sys/inc/adm_check.php';
require_once H . 'sys/inc/user.php';
user::access('adm_menu', null, 'index.php?' . SID);
adm_check();
$set['title'] = 'Меню';
require_once H . 'sys/inc/thead.php';
aut();
err();
if (isset($_POST['add']) && isset($_POST['name']) && $_POST['name'] != NULL && isset($_POST['url']) && $_POST['url'] != NULL && isset($_POST['counter'])) {
$name = text::esc(stripcslashes(htmlspecialchars($_POST['name'])));
$url = text::esc(stripcslashes(htmlspecialchars($_POST['url'])));
$counter = text::esc(stripcslashes(htmlspecialchars($_POST['counter'])));
$pos = mysql_result(mysql_query("SELECT MAX(`pos`) FROM `umenu`"), 0) + 1;
$icon = preg_replace('#[^a-z0-9 _-.]#i', null, $_POST['icon']);
mysql_query("INSERT INTO `umenu` (`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 = text::esc(stripcslashes(htmlspecialchars($_POST['name'])));
$url = text::esc(stripcslashes(htmlspecialchars($_POST['url'])));
$counter = text::esc(stripcslashes(htmlspecialchars($_POST['counter'])));
$icon = preg_replace('#[^a-z0-9 _-.]#i', null, $_POST['icon']);
mysql_query("UPDATE `umenu` 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 `umenu` WHERE `id` = '" . intval($_GET['id']) . "'"), 0)) {
$menu = mysql_fetch_assoc(mysql_query("SELECT * FROM `umenu` WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1"));
if ($_GET['act'] == 'up') {
mysql_query("UPDATE `umenu` SET `pos` = '" . ($menu['pos']) . "' WHERE `pos` = '" . ($menu['pos'] - 1) . "' LIMIT 1");
mysql_query("UPDATE `umenu` SET `pos` = '" . ($menu['pos'] - 1) . "' WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1");
msg('Пункт меню сдвинут на позицию вверх');
header("Refresh: 1; url=?");
}
if ($_GET['act'] == 'down') {
mysql_query("UPDATE `umenu` SET `pos` = '" . ($menu['pos']) . "' WHERE `pos` = '" . ($menu['pos'] + 1) . "' LIMIT 1");
mysql_query("UPDATE `umenu` 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 `umenu` WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1");
msg('Пункт меню удален');
header("Refresh: 1; url=?");
}
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `umenu`"), 0);
#Если нет разделов меню
if ($k_post == 0) {
echo "<div class='list-group-item'>";
echo "<h3><span class='label label-danger'><span class='glyphicon glyphicon-warning-sign'></span> Нет разделов меню...</span></h3>";
echo "</div>";
}
$q = mysql_query("SELECT * FROM `umenu` 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 `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`");
}
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 "<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 "<div 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 "</div>";
echo "<small>Счетчик: " . ($post['counter'] == null ? 'отсутствует' : $post['counter']) . "</small>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='' />";
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>";
}
if (user::access('adm_panel_show')) {
echo "<div class='list-group-item'><a href='/panel/'><span class='fa fa-arrow-left'></span> Панель управления</a></div>";
}
require_once H . 'sys/inc/tfoot.php';