Файл: admin.php
Строк: 261
<?php
session_start();
error_reporting(E_ALL^E_DEPRECATED);
include "sys/system.page.php";
include "sys/system.db.php";
include "sys/system.auth.php";
include "sys/system.files.php";
include "sys/system.comments.php";
include "sys/system.chat.php";
class Page {
var $gen;
var $auth;
var $db;
var $files;
var $comments;
var $config;
var $chat;
function __construct() {
global $gen;
global $auth;
global $db;
global $files;
global $comments;
global $config;
global $chat;
$gen = new PageGenerator();
$db = new Database;
$auth = new Authorization;
$files = new Files;
$comments = new Comments;
$config = new Config;
$chat = new Chat;
}
function DoFiles() {
global $gen;
global $auth;
global $db;
global $files;
global $comments;
$gen->CreateText("Все файлы:");
$arr = $files->GetFilesByCategory($db, "programs");
$listprograms = true;
if($arr == 0) {
$listprograms = false;
}
if(count($arr) == 0) {
$listprograms = false;
}
if($listprograms == true) {
for($i = 1; $i < count($arr) + 1; $i++) {
$gen->CreateLinkWithIcon("folder", $arr[$i]["name"], "files.php?fileid=" . $arr[$i]["id"]);
}
}
$arr = $files->GetFilesByCategory($db, "music");
$listmusic = true;
if($arr == 0) {
$listmusic = false;
}
if(count($arr) == 0) {
$listmusic = false;
}
if($listmusic == true) {
for($i = 1; $i < count($arr) + 1; $i++) {
$gen->CreateLinkWithIcon("music", $arr[$i]["name"], "files.php?fileid=" . $arr[$i]["id"]);
}
}
$arr = $files->GetFilesByCategory($db, "pictures");
$listpictures = true;
if(count($arr) == 0) {
$listpictures = false;
}
if($arr == 0) {
$listpictures = false;
}
if($listpictures == true) {
for($i = 1; $i < count($arr) + 1; $i++) {
$gen->CreateLinkWithIcon("file-picture-o", $arr[$i]["name"], "files.php?fileid=" . $arr[$i]["id"]);
}
}
$gen->CreateBackLink();
}
function DoChat() {
global $gen;
global $auth;
global $db;
global $files;
global $comments;
global $config;
$cfg = $config->GetConfig($db);
$gen->CreateLinkWithIcon("wrench", "Очистить чат", "admin.php?action=clearchat");
$gen->StartForm("admin.php?action=configurechat");
$gen->CreateText("Максимальное кол-во сообщений в чате:");
$gen->CreateInputWithValue("maxmsg", $cfg["maxmsg"]);
$gen->CreateCheckbox("canbannedwritetochat", "Забаненые могут писать в чат");
$gen->CreateSubmit();
$gen->CreateBackLink();
$gen->EndForm();
}
function DoConfigureChat() {
global $gen;
global $auth;
global $db;
global $files;
global $comments;
global $config;
if(isset($_POST["canbannedwritetochat"]) && $_POST["canbannedwritetochat"] == "on") {
$config->SetMaxMsg($db, $_POST["maxmsg"]);
$config->SetCanBannedSendMessages($db, "1");
$config->SetStyle($db, $config->GetConfig($db)["style"]);
echo "<script language="javascript">window.location = "admin.php?action=ok";</script>";
} else {
$config->SetMaxMsg($db, $_POST["maxmsg"]);
$config->SetCanBannedSendMessages($db, "0");
$config->SetStyle($db, $config->GetConfig($db)["style"]);
echo "<script language="javascript">window.location = "admin.php?action=ok";</script>";
}
}
function DoServerInfo() {
global $gen;
global $auth;
global $db;
global $files;
global $comments;
global $config;
$gen->CreateText("Версия PHP: " . phpversion());
$gen->CreateText("Корневая папка домена: " . $_SERVER['DOCUMENT_ROOT']);
$gen->CreateText("IP сервера: " . $_SERVER['SERVER_ADDR']);
$gen->CreateText("Имя сервера: " . $_SERVER['SERVER_NAME']);
$gen->CreateText("Сервер: " . $_SERVER['SERVER_SOFTWARE']);
$gen->CreateText("Хост: " . $_SERVER['HTTP_HOST']);
$gen->CreateBackLink();
}
function DoSQLQuery() {
global $gen;
global $auth;
global $db;
global $files;
global $comments;
global $config;
$gen->StartForm("admin.php?action=sqlquery");
$gen->CreateText("MySQL запрос:");
$gen->CreateInput("sql");
$gen->CreateSubmit();
$gen->EndForm();
$gen->CreateBackLink();
}
function DoStyle() {
global $gen;
global $auth;
global $db;
global $files;
global $comments;
global $config;
$gen->StartForm("admin.php?action=changestyle");
$gen->CreateText("Имя стиля:");
$gen->CreateInputWithValue("style", $config->GetConfig($db)["style"]);
$gen->CreateSubmit();
$gen->EndForm();
$gen->CreateBackLink();
}
function Render() {
global $gen;
global $auth;
global $db;
global $chat;
global $config;
$gen->CreateText("Админка:");
if(isset($_GET["razdel"]) && $_GET["razdel"] == "users") {
echo "<script language="javascript">window.location = "users.php";</script>";
exit;
}
if(isset($_GET["razdel"]) && $_GET["razdel"] == "files") {
$this->DoFiles();
exit;
}
if(isset($_GET["razdel"]) && $_GET["razdel"] == "chat") {
$this->DoChat();
exit;
}
if(isset($_GET["razdel"]) && $_GET["razdel"] == "serverinfo") {
$this->DoServerInfo();
exit;
}
if(isset($_GET["razdel"]) && $_GET["razdel"] == "sqlquery") {
$this->DoSQLQuery();
exit;
}
if(isset($_GET["razdel"]) && $_GET["razdel"] == "style") {
$this->DoStyle();
exit;
}
if(isset($_GET["action"]) && $_GET["action"] == "clearchat") {
$chat->Clear($db);
echo "<script language="javascript">window.location = "admin.php?action=ok";</script>";
exit;
}
if(isset($_GET["action"]) && $_GET["action"] == "configurechat") {
$this->DoConfigureChat();
exit;
}
if(isset($_GET["action"]) && $_GET["action"] == "sqlquery") {
$arr = $db->QueryAndFetch($_POST["sql"]);
$gen->CreateText("Ответ MySQL: ");
echo "<div class="content-field">";
print_r($arr);
echo "</div>";
$gen->CreateBackLink();
exit;
}
if(isset($_GET["action"]) && $_GET["action"] == "changestyle") {
if(!file_exists("css/style-" . $_POST["style"] . ".css")) {
$gen->CreateText("Такого стиля не существует!");
$gen->CreateBackLink();
exit;
}
$config->SetStyle($db, $_POST["style"]);
echo "<script language="javascript">window.location = "admin.php?action=ok";</script>";
exit;
}
if(isset($_GET["action"]) && $_GET["action"] == "ok") {
$gen->CreateText("Настройки успешно сохранены");
$gen->CreateBackLink();
exit;
}
if(!$auth->GetUserRights($db) == "Администратор" or !$auth->GetUserRights($db) == "Создатель") {
$gen->CreateText("<b style="color: red">У вас нет прав для доступа к админке!</b>");
exit;
}
$gen->CreateLinkWithIcon("user", "Пользователи", "admin.php?razdel=users");
$gen->CreateLinkWithIcon("folder", "Файлы", "admin.php?razdel=files");
$gen->CreateLinkWithIcon("comment", "Настройки чата", "admin.php?razdel=chat");
$gen->CreateLinkWithIcon("wrench", "Информация о сервере", "admin.php?razdel=serverinfo");
$gen->CreateLinkWithIcon("database", "MySQL", "admin.php?razdel=sqlquery");
$gen->CreateLinkWithIcon("wrench", "Стили", "admin.php?razdel=style");
$gen->CreateBackLink();
}
}
$index = new Page;
$index->Render();
?>