Файл: panel/profile.php
Строк: 285
<?php
/* DCMS S (Special)
* Версия файла 0.0.1
* Дата последнего редактирования 12.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_profile', null, 'index.php?' . SID);
adm_check();
$set['title'] = 'Профиль';
require_once H . 'sys/inc/thead.php';
$opendiricon = opendir(H . 'style/icons');
while ($icons = readdir($opendiricon)) {
#запись всех тем в массив
if (preg_match('#^.|default.png#', $icons)) {
continue;
}
$icon[] = $icons;
}
closedir($opendiricon);
title();
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 `profile`"), 0) + 1;
$icon = preg_replace('#[^a-z0-9 _-.]#i', null, $_POST['icon']);
$private = text::esc(stripcslashes(htmlspecialchars($_POST['private'])));
mysql_query("INSERT INTO `profile` (`name`, `private`, `url`, `counter`, `pos`, `icon`) VALUES ('$name', '$private', '$url', '$counter', '$pos', '$icon')");
msg('Ссылка успешно добавлена');
}
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 `profile` 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 `profile` WHERE `id` = '" . intval($_GET['id']) . "'"), 0)) {
$menu = mysql_fetch_assoc(mysql_query("SELECT * FROM `profile` WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1"));
if ($_GET['act'] == 'up') {
mysql_query("UPDATE `profile` SET `pos` = '" . ($menu['pos']) . "' WHERE `pos` = '" . ($menu['pos'] - 1) . "' LIMIT 1");
mysql_query("UPDATE `profile` SET `pos` = '" . ($menu['pos'] - 1) . "' WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1");
msg('Пункт меню сдвинут на позицию вверх');
}
if ($_GET['act'] == 'down') {
mysql_query("UPDATE `profile` SET `pos` = '" . ($menu['pos']) . "' WHERE `pos` = '" . ($menu['pos'] + 1) . "' LIMIT 1");
mysql_query("UPDATE `profile` SET `pos` = '" . ($menu['pos'] + 1) . "' WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1");
msg('Пункт меню сдвинут на позицию вниз');
}
if ($_GET['act'] == 'del') {
mysql_query("DELETE FROM `profile` WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1");
msg('Пункт меню удален');
}
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `profile`"), 0);
#Если нет разделов меню
if ($k_post == 0) {
echo "<div class='comm'>";
echo "<h3><span class='label label-danger'><span class='glyphicon glyphicon-warning-sign'></span> Нет разделов меню...</span></h3>";
echo "</div>";
}
$q = mysql_query("SELECT * FROM `profile` 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 = 'comm'>";
if (!isset($post['icon'])) {
mysql_query('ALTER TABLE `profile` ADD `icon` VARCHAR( 32 ) NULL DEFAULT NULL');
}
if (!isset($post['type'])) {
mysql_query("ALTER TABLE `profile` 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 = 'comm' action = '?id=$post[id]' method = 'post'>";
echo "Тип: " . ($post['type'] == 'link' ? 'Ссылка' : '') . "<br />";
echo "Кому видно? ";
if ($post['private'] == '0') {
echo "Всем";
} elseif ($post['private'] == '1') {
echo "Только мне";
} elseif ($post['private'] == '2') {
echo "Мне не видно";
} else {
echo "Неизвестно";
}
echo "<br />";
echo "<input class='form-control' type = 'text' name = 'name' value = '$post[name]' /><br />";
if ($post['type'] == 'link') {
echo "<input class='form-control' type = 'text' name = 'url' value = '$post[url]' /><br />";
} else {
echo "<input class='form-control' type = 'hidden' name = 'url' value = '' />";
}
echo "<input class='form-control' placeholder = 'Счетчик' type = 'text' name = 'counter' value = '$post[counter]' /><br />";
if ($post['type'] == 'link') {
echo '
<div class="input-group">
<input type="text" class="form-control" name = "icon" value = "' . $post['icon'] . '">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Действие <span class="caret"></span></button>
<ul class="dropdown-menu pull-right">
<li><a href="/user/icons.php">Список иконок</a></li>
</ul>
</div>
</div>';
} else {
echo "<input type = 'hidden' name = 'icon' value = '$post[icon]' />";
}
echo "<br />";
echo "<div style = 'float:right;' class='close'>";
echo "<a href = '?$passgen' title = 'Отмена'><span class='glyphicon glyphicon-remove'></span></a>";
echo "</div>";
echo "<button name = 'change' class = 'btn btn-success'><span class='glyphicon glyphicon-floppy-disk'></span> Сохранить</button>";
echo "</form>";
} else {
echo "<div class = 'comm'>";
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 "<font color = 'grey'><small>Файл: " . ($post['type'] == 'link' ? "$post[url]" : null) . "<br />";
echo "<div style = 'float:right;color:grey;'>";
echo "<a href = '?id=$post[id]&act=edit&$passgen' title = 'Редактировать'><span class='glyphicon glyphicon-pencil'></span></a> ";
echo "<a href = '?id=$post[id]&act=del&$passgen' title = 'Удалить'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</div>";
echo "Кому видно: ";
if ($post['private'] == '0') {
echo "Всем";
} elseif ($post['private'] == '1') {
echo "Только мне";
} elseif ($post['private'] == '2') {
echo "Мне не видно";
} else {
echo "Неизвестно";
}
echo "<br />";
echo "Счетчик: " . ($post['counter'] == null ? 'отсутствует' : $post['counter']) . "</small></font>n";
echo "</div>";
}
}
if (isset($_GET['add'])) {
echo "<form action = '?add=$passgen' class = 'comm' method = 'post'>";
echo '<div class="panel-body">';
echo "<select name = 'type' class='form-control'>";
echo "<option value = 'link'>Ссылка *</option>";
echo "</select><br />";
echo "Кому видно?:<br />";
echo "<select class='form-control' name='private'>";
echo "<option value='0'>Всем</option>";
echo "<option value='1'>Только мне</option>";
echo "<option value='2'>Мне не видно</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 '<div class="input-group"><input type="text" class="form-control" placeholder = "Иконка" name = "icon" value = "">
<div class="input-group-btn"><button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Действие <span class="caret"></span></button>
<ul class="dropdown-menu pull-right"><li><a href="/user/icons.php">Список иконок</a></li></ul>
</div></div>';
echo "<br />";
echo "<div style = 'float:right;' class='close'>";
echo "<a href = '?$passgen' title = 'Отмена'><span class='glyphicon glyphicon-remove'></span></a>";
echo "</div>";
echo "<button name = 'add' class = 'btn btn-success'><span class='glyphicon glyphicon-plus'></span> Добавить</button>";
echo "</div></form>";
} else {
echo "<form action = '?add=$passgen' class = 'comm' method = 'post'>";
echo "<button class = 'btn btn-success'><span class='glyphicon glyphicon-plus'></span> Добавить пункт</button>";
echo "</form>";
}
if (user::access('adm_panel_show')) {
echo "<div class = 'comm'><a href = '/panel/' style = 'color:#88C057;'><img src = '/style/icons/left.png' /> Панель управления</a></div>";
}
require_once H . 'sys/inc/tfoot.php';