Файл: panel/games.php
Строк: 185
<?php
/* DCMS Special
* Дата последнего редактирования 23.01.2016
* Модифицировал densnet
*/
foreach (array('start', 'compress', 'sess', 'settings', 'db_connect', 'ipua', 'fnc', 'adm_check', 'user') as $inc) {
require_once "../sys/inc/$inc.php";
}
access('adm_games', null, 'index.php?' . SID);
adm_check();
$set['title'] = lang('Игры и приложения');
require_once H . 'sys/inc/thead.php';
aut();
err();
#Навигация
echo "<div class='list-group-item-null list-group-item-grey'><small>";
echo "<a href='/' class='hint--right' data-hint='" . lang('На главную') . "'><i class='fa fa-home fa-lg'></i></a> <i class='fa fa-angle-right fa-fw'></i> ";
echo "<a href='/panel/'>" . lang('Панель управления') . "</a> <i class='fa fa-angle-right fa-fw'></i> ";
echo lang('Игры и приложения');
echo "</small></div><br />";
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'])));
$opis = esc(stripcslashes(htmlspecialchars($_POST['opis'])));
$url = esc(stripcslashes(htmlspecialchars($_POST['url'])));
$counter = esc(stripcslashes(htmlspecialchars($_POST['counter'])));
$pos = mysql_result(mysql_query("SELECT MAX(`pos`) FROM `games`"), 0) + 1;
$icon = preg_replace('#[^a-z0-9 _-.]#i', null, $_POST['icon']);
mysql_query("INSERT INTO `games` (`name`, `opis`, `url`, `counter`, `pos`, `icon`) VALUES ('$name', '$opis', '$url', '$counter', '$pos', '$icon')");
$_SESSION['message'] = lang('Приложение успешно добавлено');
header("Location: ?");
}
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'])));
$opis = esc(stripcslashes(htmlspecialchars($_POST['opis'])));
$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 `games` SET `name` = '$name', `opis` = '$opis', `url` = '$url', `counter` = '$counter', `icon` = '$icon' WHERE `id` = '$id' LIMIT 1");
$_SESSION['message'] = lang('Изменения сохранены');
header("Location: ?");
}
if (isset($_GET['id']) && isset($_GET['act']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `games` WHERE `id` = '" . intval($_GET['id']) . "'"), 0)) {
$menu = mysql_fetch_assoc(mysql_query("SELECT * FROM `games` WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1"));
if ($_GET['act'] == 'up') {
mysql_query("UPDATE `games` SET `pos` = '" . ($menu['pos']) . "' WHERE `pos` = '" . ($menu['pos'] - 1) . "' LIMIT 1");
mysql_query("UPDATE `games` SET `pos` = '" . ($menu['pos'] - 1) . "' WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1");
$_SESSION['message'] = lang('Изменения сохранены');
header("Location: ?");
}
if ($_GET['act'] == 'down') {
mysql_query("UPDATE `games` SET `pos` = '" . ($menu['pos']) . "' WHERE `pos` = '" . ($menu['pos'] + 1) . "' LIMIT 1");
mysql_query("UPDATE `games` SET `pos` = '" . ($menu['pos'] + 1) . "' WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1");
$_SESSION['message'] = lang('Изменения сохранены');
header("Location: ?");
}
if ($_GET['act'] == 'del') {
mysql_query("DELETE FROM `games` WHERE `id` = '" . intval($_GET['id']) . "' LIMIT 1");
$_SESSION['message'] = lang('Пункт удален');
header("Location: ?");
}
}
$k_post = mysql_result(mysql_query("SELECT COUNT(*) FROM `games`"), 0);
#Если нет разделов меню
if ($k_post == 0) {
$doc->NoResult();
}
$q = mysql_query("SELECT * FROM `games` 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-null'>";
if (!isset($post['icon'])) {
mysql_query('ALTER TABLE `games` ADD `icon` VARCHAR( 32 ) NULL DEFAULT NULL');
}
echo "<img src='/modules/games/img/$post[icon]' width='20'/>";
echo "<div style='float:right;color:grey;'>$post[pos]</div>";
echo "$post[pos]. $post[name] ($post[url])";
echo "</div>";
echo "<form class='list-group-item-null' action='?id=$post[id]' method='post'>";
echo "<input placeholder='Название' type='text' name='name' value='$post[name]' class='form-control'/><br />";
echo "<textarea placeholder='Описание' name='opis' class='form-control'/>$post[opis]</textarea><br />";
echo "<input placeholder='Ссылка' type='text' name='url' value='$post[url]' class='form-control'/><br />";
echo "<input placeholder='Счетчик' type='text' name='counter' value='$post[counter]' class='form-control'/><br />";
echo "<input placeholder='Иконка 48x48' type='text' name='icon' value='$post[icon]' class='form-control'/>";
echo "<br />";
echo "<button name='change' class='btn btn-success btn-sm'><i class='fa fa-save fa-fw'></i> Сохранить</button> ";
echo "<a class='btn btn-sm btn-secondary' href='?$passgen'>Отмена</a>";
echo "</form>";
} else {
echo "<div class='list-group-item-null'>";
if (!isset($post['icon'])) {
mysql_query('ALTER TABLE `games` ADD `icon` VARCHAR( 32 ) NULL DEFAULT NULL');
}
echo "<span style='float:right;color:grey;'>";
echo "<a href='?id=$post[id]&act=edit&$passgen' title='Редактировать'><i class='fa fa-edit fa-fw'></i></a> ";
echo "<a href='?id=$post[id]&act=up&$passgen' title='Выше'><i class='fa fa-arrow-up fa-fw'></i></a> ";
echo "</span>";
echo "<img src='/modules/games/img/$post[icon]' width='20'/>";
echo " $post[name]<br />";
echo "<font color='grey'>";
echo "<small>Ссылка: $post[url]</small><br />";
echo "<small>Счетчик: " . ($post['counter'] == null ? 'отсутствует' : $post['counter']) . "</small>";
echo "</font>n";
echo "<span style='float:right;color:grey;'>";
echo "<a href='?id=$post[id]&act=del&$passgen' title='Удалить'><i class='fa fa-trash-o 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 "</div>n";
}
}
if (isset($_GET['add'])) {
echo "<form action='?add=$passgen' class='list-group-item-null' method='post'>";
echo "<input placeholder='Название' type='text' name='name' value='' class='form-control'/><br />";
echo "<textarea placeholder='Описание' name='opis' class='form-control'/></textarea><br />";
echo "<input placeholder='Ссылка' type='text' name='url' value='' class='form-control'/><br />";
echo "<input placeholder='Счетчик' type='text' name='counter' value='' class='form-control'/>";
echo "<small style='color: grey;'>Имя иконки (gorod.png) иконку кинуть в /modules/games/img/</small>";
echo "<input placeholder='Иконка 48x48' type='text' name='icon' value='' class='form-control'/>";
echo "<br />";
echo "<button name='add' class='btn btn-primary btn-sm'><i class='fa fa-plus fa-fw'></i> Добавить</button> ";
echo "<a class='btn btn-sm btn-secondary' href='?$passgen'>Отмена</a>";
echo "</form>";
} else {
echo "<form action='?add=$passgen' class='list-group-item-null' method='post'>";
echo "<button class='btn btn-primary btn-sm'><i class='fa fa-plus fa-fw'></i> Добавить пункт</button>";
echo "</form>";
}
require_once H . 'sys/inc/tfoot.php';