Файл: soc-set/panel/chat.php
Строк: 88
<?php
require_once('../core/start.php');
check_auth();
head('Управление чатом');
echo DIV_TITLE . 'Управление чатом' . CLOSE_DIV;
if (privilegy('chat') == FALSE) {
header("Location: ".HOME."/panel");
exit();
}
$all = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".CHAT_MSG." ");
if (isset($_GET['clean'])) {
DB::$dbs->query("TRUNCATE ".CHAT_MSG."");
header("Location: ".HOME."/panel/chat/");
}
if (!empty($_GET['cleanroom'])) {
DB::$dbs->query("DELETE FROM ".CHAT_MSG." WHERE `room_id` = ? ", array(num($_GET['cleanroom'])));
header("Location: ".HOME."/panel/chat/");
}
if (!empty($_GET['delroom'])) {
if (!isset($_GET['go'])) {
echo DIV_LI . '<b>Подтвердите удаление:</b> <a href="'.HOME.'/panel/chat/?delroom='.(int)$_GET['delroom'].'&go">[Удалить]</a> <a href="'.HOME.'/panel/chat/">[Нет]</a>' . CLOSE_DIV;
} else {
DB::$dbs->query("DELETE FROM ".CHAT_MSG." WHERE `room_id` = ? ", array(num($_GET['delroom'])));
DB::$dbs->query("DELETE FROM ".CHAT_ROOM." WHERE `id` = ? ", array(num($_GET['delroom'])));
header("Location: ".HOME."/panel/chat/");
}
}
if (!empty($_POST['str'])) {
$str = num($_POST['str']);
if (empty($str)) {
echo DIV_ERROR . 'Пустое значение' . CLOSE_DIV;
} else {
DB::$dbs->query("UPDATE ".CONFIG." SET `write_room` = ? ", array($str));
header("Location: ".HOME."/panel/chat/");
}
}
if (!empty($_GET['editroom'])) {
if ($_POST['edit']) {
$room = html($_POST['room']);
$type = num($_POST['type']);
if (empty($room)) {
echo DIV_ERROR . 'Не указано название комнаты' . CLOSE_DIV;
} else {
DB::$dbs->query("UPDATE ".CHAT_ROOM." SET `name` = ?, `type` = ? WHERE `id` = ?", array($room, $type, num($_GET['editroom'])));
header("Location: ".HOME."/panel/chat/");
}
}
$room = DB::$dbs->queryFetch("SELECT `name`, `type` FROM ".CHAT_ROOM." WHERE `id` = ?",array(num($_GET['editroom'])));
echo DIV_AUT;
echo '<form action="#" method="POST">';
echo 'Название:<br /><input type="text" value="'.$room['name'].'" name="room" /><br />';
echo '<select name="type">';
echo '<option '.(0 == $room['type'] ? 'selected="selected"' : NULL).' value="0">Обычная</option>';
echo '<option '.(1 == $room['type'] ? 'selected="selected"' : NULL).' value="1">С ботом "Умник"</option>';
echo '<option '.(2 == $room['type'] ? 'selected="selected"' : NULL).' value="2">С ботом "Шутник"</option>';
echo '</select>';
echo '<input type="submit" name="edit" value="Изменить" /></form>';
echo CLOSE_DIV;
}
echo DIV_LI . 'Сообщений в чате: <b>' . $all . '</b> <a href="?clean">[Очистить]</a>' . CLOSE_DIV;
$all = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".CHAT_ROOM."");
if (empty($all)) {
echo DIV_BLOCK . 'Комнаты не созданы' . CLOSE_DIV;
} else {
$sql = DB::$dbs->query("SELECT * FROM ".CHAT_ROOM." ORDER BY `id` DESC");
while($room = $sql -> fetch()) {
echo DIV_BLOCK;
echo '<a href="'.HOME.'/chat/'.$room['id'].'/">'.$room['name'].'</a><br />';
$allmsg = DB::$dbs->querySingle("SELECT COUNT(`id`) FROM ".CHAT_MSG." WHERE `room_id` = ? ", array($room['id']));
echo 'Сообщений: <b>' . $allmsg . '</b> <a href="?cleanroom='.$room['id'].'">[Очистить]</a> <a href="?delroom='.$room['id'].'">[Удал.]</a> <a href="?editroom='.$room['id'].'">[Ред.]</a><br />';
echo CLOSE_DIV;
}
}
if ($_POST['add']) {
$room = html($_POST['room']);
$type = num($_POST['type']);
if (empty($room)) {
echo DIV_ERROR . 'Не указано название комнаты' . CLOSE_DIV;
} else {
DB::$dbs->query("INSERT INTO ".CHAT_ROOM." (`name`, `type`) VALUES (?, ?)", array($room, $type));
header("Location: ".HOME."/panel/chat/");
}
}
echo DIV_AUT;
echo '<form action="#" method="POST">';
echo 'Новая комната:<br /><input type="text" name="room" /><br />';
echo '<select name="type">';
echo '<option value="0">Обычная</option>';
echo '<option value="1">С ботом "Умник"</option>';
echo '<option value="2">С ботом "Шутник"</option>';
echo '</select>';
echo '<input type="submit" name="add" value="+" /></form>';
echo CLOSE_DIV;
echo DIV_AUT;
echo '<b>Сообщений на страницу:</b><br />';
echo '<form action="#" method="POST">';
echo '<select name="str">';
echo '<option '.(5 == $config['write']['room'] ? 'selected="selected"' : NULL).' value="5">5</option>';
echo '<option '.(10 == $config['write']['room'] ? 'selected="selected"' : NULL).' value="10">10</option>';
echo '<option '.(15 == $config['write']['room'] ? 'selected="selected"' : NULL).' value="15">15</option>';
echo '<option '.(20 == $config['write']['room'] ? 'selected="selected"' : NULL).' value="20">20</option>';
echo '<option '.(30 == $config['write']['room'] ? 'selected="selected"' : NULL).' value="30">30</option>';
echo '<option '.(50 == $config['write']['room'] ? 'selected="selected"' : NULL).' value="50">50</option>';
echo '</select>';
echo '<input type="submit" name="sett" value="Изменить" /></form>';
echo CLOSE_DIV;
echo DIV_GO . '<a href="'.HOME.'/">Главная</a> / <a href="'.HOME.'/panel">Панель управления</a> / <b>Управление чатом</b>' . CLOSE_DIV;
require_once('../core/stop.php');
?>