Файл: adm_panel/menu.php
Строк: 311
<?php
/* Мод "Панель управления"
* Версия v0.0.1
* Дата последнего редактирования 31.01.2015
* Двиг DCMS Special
* Модифицировал densnet
* Файл menu.php
* Описание: Редактирование главного меню
*/
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';
$opendiricon = opendir(H . 'style/img/menu');
while ($icons = readdir($opendiricon)) {
#запись всех тем в массив
if (preg_match('#^.|default.png#', $icons)) {
continue;
}
$icon[] = $icons;
}
closedir($opendiricon);
title();
err();
aut();
if (isset($_POST['add']) && isset($_POST['name']) && $_POST['name'] != NULL && isset($_POST['url']) && $_POST['url'] != NULL && isset($_POST['include']) && isset($_POST['counter'])) {
$name = text::esc(stripcslashes(htmlspecialchars($_POST['name'])));
$url = text::esc(stripcslashes(htmlspecialchars($_POST['url'])));
$include = text::esc(stripcslashes(htmlspecialchars($_POST['include'])));
$counter = text::esc(stripcslashes(htmlspecialchars($_POST['counter'])));
$pos = mysql_result(mysql_query("SELECT MAX(`pos`) FROM `menu`"), 0) + 1;
$icon = preg_replace('#[^a-z0-9 _-.]#i', null, $_POST['icon']);
mysql_query("INSERT INTO `menu` (`name`, `url`, `include`, `counter`, `pos`, `icon`) VALUES ('$name', '$url', '$include', '$counter', '$pos', '$icon')");
msg('Ссылка успешно добавлена');
}
if (isset($_POST['add']) && isset($_POST['name']) && $_POST['name'] != NULL && isset($_POST['counter']) && isset($_POST['include']) && isset($_POST['type']) && $_POST['type'] == 'razd') {
$name = text::esc(stripcslashes(htmlspecialchars($_POST['name'])));
$url = text::esc(stripcslashes(htmlspecialchars($_POST['url'])));
$include = text::esc(stripcslashes(htmlspecialchars($_POST['include'])));
$counter = text::esc(stripcslashes(htmlspecialchars($_POST['counter'])));
$pos = mysql_result(mysql_query("SELECT MAX(`pos`) FROM `menu`"), 0) + 1;
$icon = preg_replace('#[^a-z0-9 _-.]#i', null, $_POST['icon']);
mysql_query("INSERT INTO `menu` (`type`, `name`, `url`, `include`, `counter`, `pos`, `icon`) VALUES ('razd', '$name', '$url', '$include', '$counter', '$pos', '$icon')");
msg('Ссылка успешно добавлена');
}
if (isset($_POST['add']) && isset($_POST['include']) && isset($_POST['type']) && $_POST['type'] == 'include') {
$name = text::esc(stripcslashes(htmlspecialchars($_POST['name'])));
$url = text::esc(stripcslashes(htmlspecialchars($_POST['url'])));
$include = text::esc(stripcslashes(htmlspecialchars($_POST['include'])));
$counter = text::esc(stripcslashes(htmlspecialchars($_POST['counter'])));
$pos = mysql_result(mysql_query("SELECT MAX(`pos`) FROM `menu`"), 0) + 1;
$icon = preg_replace('#[^a-z0-9 _-.]#i', null, $_POST['icon']);
mysql_query("INSERT INTO `menu` (`type`, `name`, `url`, `include`, `counter`, `pos`, `icon`) VALUES ('include', '$name', '$url', '$include', '$counter', '$pos', '$icon')");
msg('Инклуд успешно добавлен');
}
if (isset($_POST['change']) && isset($_GET['id']) && isset($_POST['name']) && $_POST['name'] != NULL && isset($_POST['url']) && isset($_POST['include']) && isset($_POST['counter'])) {
$id = intval($_GET['id']);
$name = text::esc(stripcslashes(htmlspecialchars($_POST['name'])));
$url = text::esc(stripcslashes(htmlspecialchars($_POST['url'])));
$include = text::esc(stripcslashes(htmlspecialchars($_POST['include'])));
$counter = text::esc(stripcslashes(htmlspecialchars($_POST['counter'])));
$icon = preg_replace('#[^a-z0-9 _-.]#i', null, $_POST['icon']);
mysql_query("UPDATE `menu` SET `name` = '$name', `url` = '$url', `include` = '$include', `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");
msg('Пункт меню удален');
}
}
echo "<div style = 'font-size: 18px;font-weight: bold;' class = 'razd'>" . img24('panel.png') . " Главное меню</div>";
$q = mysql_query("SELECT * FROM `menu` ORDER BY `pos` ASC");
while ($post = mysql_fetch_assoc($q)) {
echo "<table class = 'razd'><tr><td class = 'null'>";
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', 'include', 'razd') NOT NULL DEFAULT 'link' AFTER `id`");
}
if ($post['type'] == 'link') {
echo icons_menu($post['icon'], 'code');
}
echo "$post[pos]) ";
if ($post['type'] == 'link' || $post['type'] == 'razd') {
echo "$post[name] " . ($post['type'] == 'link' ? "($post[url])" : null);
}
if ($post['type'] == 'include') {
echo "Инклуд";
}
echo "<br />";
if (isset($_GET['id']) && $_GET['id'] == $post['id'] && isset($_GET['act']) && $_GET['act'] == 'edit') {
echo "<form action = '?id=$post[id]' method = 'post'>";
echo "Тип: ";
if ($post['type'] == 'link') {
echo 'Ссылка';
} elseif ($post['type'] == 'razd') {
echo 'Раздел';
} elseif ($post['type'] == 'include') {
echo 'Инклуд';
}
echo "<br />";
echo "Название:<br />";
echo "<input type = 'text' name = 'name' value = '$post[name]' /><br />";
if ($post['type'] == 'link') {
echo "Ссылка:<br />";
echo "<input type = 'text' name = 'url' value = '$post[url]' /><br />";
} else {
echo "<input type = 'hidden' name = 'url' value = '' />";
}
if ($post['type'] == 'include') {
echo "Инклуд:<br />";
echo "<input type = 'text' name = 'include' value = '$post[include]' /><br />";
} else {
echo "<input type = 'hidden' name = 'include' value = '' />";
}
echo "Счетчик:<br />";
echo "<input type = 'text' name = 'counter' value = '$post[counter]' /><br />";
if ($post['type'] == 'link') {
echo "Иконка:<br />";
echo "<select name = 'icon'>n";
echo "<option value = 'default.png'>По умолчанию</option>n";
for ($i = 0; $i < sizeof($icon); $i++) {
echo "<option value = '$icon[$i]'" . ($post['icon'] == $icon[$i] ? " selected = 'selected'" : null) . ">$icon[$i]</option>n";
}
echo "</select><br />";
} else {
echo "<input type = 'hidden' name = 'icon' value = '$post[icon]' />";
}
echo "<div style = 'float:right;' id = 'hide'>";
echo "<a href = '?$passgen' title = 'Отмена'>" . img16('cancel.png') . "</a>";
echo "</div>";
echo "<button name = 'change' class = 'button sign-ins'>" . img16('save.png') . " Сохранить";
echo "</button></form>";
} else {
if ($post['type'] == 'include') {
echo "Инклуд: " . ($post['include'] == null ? 'отсутствует' : $post['include']) . "<br />n";
}
echo "Счетчик: " . ($post['counter'] == null ? 'отсутствует' : $post['counter']) . "<br /><br />n";
echo "<a class = 'add' href='?id=$post[id]&act=up&$passgen' title = 'Поднять выше'>" . img16('up.png') . "</a> ";
echo "<a class = 'add' href='?id=$post[id]&act=down&$passgen' title = 'Опустить ниже'>" . img16('down.png') . "</a> ";
echo "<a class = 'add' href='?id=$post[id]&act=del&$passgen' title = 'Удалить'>" . img16('musor.png') . "</a> ";
echo "<a class = 'add' href='?id=$post[id]&act=edit&$passgen' title = 'Редактировать'>" . img16('set.png') . "</a>";
}
echo "</td></tr></table>";
}
if (isset($_GET['add'])) {
echo "<form action = '?add=$passgen' class = 'razd' method = 'post'>";
echo "<b>Тип</b><br />";
echo "<select name = 'type'>";
echo "<option value = 'link'>Ссылка (1)</option>";
echo "<option value = 'razd'>Раздел (2)</option>";
echo "<option value = 'include'>Инклуд (3)</option>";
echo "</select><br />";
echo "<b>Название (1,2)</b><br />";
echo "<input type = 'text' name = 'name' value = '' /><br />";
echo "<b>Ссылка(1)</b><br />";
echo "<input type = 'text' name = 'url' value = '' /><br />";
echo "<b>Инклуд(3)</b><br />";
echo "<input type = 'text' name = 'include' value = '' /><br />";
echo "<b>Счетчик (1,2)</b><br />";
echo "<input type = 'text' name = 'counter' value = '' /><br />";
echo "<b>Иконка (1)</b><br />";
echo "<select name = 'icon'>";
echo "<option value = 'default.png'>По умолчанию</option>";
for ($i = 0; $i < sizeof($icon); $i++) {
echo "<option value = '$icon[$i]'>$icon[$i]</option>";
}
echo "</select><br />";
echo "<div style = 'float:right;' id = 'hide'>";
echo "<a href = '?$passgen' title = 'Отмена'>" . img16('cancel.png') . "</a>";
echo "</div>";
echo "<button name = 'add' class = 'button sign-ins'>Добавить";
echo "</button></form>";
} else {
echo "<form action = '?add=$passgen' class = 'razd' method = 'post'>";
echo "<button class = 'button sign-ins'>Добавить пункт";
echo "</button></form>";
}
if (user::access('adm_panel_show')) {
echo "<div class = 'razd'><a href = '/adm_panel/' class = 'add'>" . img16('left.png') . " Панель управления</a></div>";
}
require_once H . 'sys/inc/tfoot.php';