View file panel/room.php

File size: 5.82Kb
<?php
include '../sys/db.php';
include '../sys/conf.php';
include '../sys/start.php';
include '../sys/functions.php';
$config_title_name = "Управление комнатами";
include '../style/head.php';
if(isset($user['login'])){
if(isset($user['level']) && $user['level']=='1'){
$act = isset($_GET['act']) ? $_GET['act'] : '';
switch($act){
default:
echo "<div class=title><b>Управление комтами</b></div>\n";
$req = mysql_query("SELECT * FROM `room` ORDER BY `position` ASC");
if (mysql_num_rows($req) > 0){
while ($res = mysql_fetch_array($req)) {
$n++;
echo "<div class=content>\n";
echo "<b>$n. </b> <a href='room.php?act=view&id=".$res['id']."'>".$res['name']."</a><br>\n";
echo "<a href='room.php?act=up&id=".$res['id']."'>Вверх</a> | \n";
echo "<a href='room.php?act=down&id=".$res['id']."'>Вниз</a> | \n";
echo "<a href='room.php?act=edit&id=".$res['id']."'>Изм.</a> | \n";
echo "<a href='room.php?act=del&id=".$res['id']."'>Удалить</a>\n";
echo "</div>\n";
++$i;}
}else{ echo "<div class=content> <br><img src='../img/lock.gif' alt=''> Комнаты не созданны\n<br> <br> \n</div>";}
echo "<div class=stat><a href='?act=add'>Добавить</a></div>\n";
echo "<div class=stat><a href='index.php'>Админка</a></div>\n";
echo "<div class=stat><a href='../index.php'>Прихожая</a></div>\n";
break;
case 'down':
$id = $_GET['id'];
if ($id){
$req = mysql_query("SELECT `position` FROM `room` WHERE `id` = '$id'");
if (mysql_num_rows($req) > 0){
$res = mysql_fetch_array($req);
$position = $res['position'];
$req = mysql_query("SELECT * FROM `room` WHERE `position` > '$position' ORDER BY `position` ASC");
if (mysql_num_rows($req) > 0){
$res = mysql_fetch_array($req);
$id2 = $res['id'];
$position2 = $res['position'];
mysql_query("UPDATE `room` SET `position` = '$position2' WHERE `id` = '$id'");
mysql_query("UPDATE `room` SET `position` = '$position' WHERE `id` = '$id2'");}}}
header("Location: room.php");
break;
case 'up':
$id = $_GET['id'];
if ($id){
$req = mysql_query("SELECT `position` FROM `room` WHERE `id` = '$id'");
if (mysql_num_rows($req) > 0){
$res = mysql_fetch_array($req);
$position = $res['position'];
$req = mysql_query("SELECT * FROM `room` WHERE `position` < '$position' ORDER BY `position` DESC");
if (mysql_num_rows($req) > 0){
$res = mysql_fetch_array($req);
$id2 = $res['id'];
$position2 = $res['position'];
mysql_query("UPDATE `room` SET `position` = '" . $position2 . "' WHERE `id` = '" . $id . "'");
mysql_query("UPDATE `room` SET `position` = '" . $position . "' WHERE `id` = '" . $id2 . "'");}}}
header("Location: room.php");
break;
case('edit'):
$id = intval($_GET['id']);
if ($id){
echo "<div class=title>Редактирование комнаты</div>\n";
echo "<div class=content>\n ";
if ($_GET['isset']==noname) {echo "Вы не ввели название!\n";}
$rooms = mysql_query("SELECT * FROM `room` WHERE `id` = '$id'");
if($room = mysql_fetch_array($rooms)){
echo "<form action='?act=editroom&id=$id' method='post' name='reg'>\n";
echo "Название: <br><input name='name' value='".$room['name']."' type='text'><br>\n";



echo "Антимат:<br>\n";
echo "Выкл ";
if($room['antimat']=="1"){echo " <input name='antimat' type='radio' value='1' checked>";
}else{echo "<input name='antimat' type='radio' value='1'>";}
echo "  |  ";
if($room['antimat']=="0"){echo "<input name='antimat' type='radio' value='0' checked>";
}else{echo "<input name='antimat' type='radio' value='0'>";}
echo "Вкл<br>\n";

echo "<br>\n";

echo "Шутник:<br>\n";
echo "Выкл ";
if($room['joker']=="0"){echo " <input name='joker' type='radio' value='0' checked>";
}else{echo "<input name='joker' type='radio' value='0'>";}
echo "  |  ";
if($room['joker']=="1"){echo "<input name='joker' type='radio' value='1' checked>";
}else{echo "<input name='joker' type='radio' value='1'>";}
echo "Вкл<br>\n";

echo "<br>\n";

echo "<input type='submit' value='Изменить'></form>\n";}
echo "</div>\n";
echo "<div class=stat><a href='room.php'>Назад</a></div>\n";
echo "<div class=stat><a href='index.php'>Админка</a></div>\n";
echo "<div class=stat><a href='../index.php'>Прихожая</a></div>\n";}
break;
case('editroom'):
$id = intval($_GET['id']);
if ($id){
$antimat = intval($_POST['antimat']);
$joker = intval($_POST['joker']);
$name = $_POST['name'];
$name = htmlspecialchars(stripslashes(trim($name)));
if ($name == '') {header ("Location: ?act=nameroom&isset=noname"); exit;}
mysql_query("UPDATE `room` SET `name` = '$name' WHERE `id` = '$id'");
mysql_query("UPDATE `room` SET `antimat` = '$antimat' WHERE `id` = '$id'");
mysql_query("UPDATE `room` SET `joker` = '$joker' WHERE `id` = '$id'");
header ("Location: room.php");  exit;}
break;
case('del'):
$id = $_GET['id'];
if ($id){
mysql_query("DELETE FROM `room` WHERE id='$id'");
header ("Location: room.php");  exit;}
break;
case('add'):
echo "<div class=title>Добавление комнаты</div>\n";
echo "<div class=content>\n";
echo "<form action='?act=addroom&' method='post' name='reg'>\n";
echo "Название комнаты: <br><input name='name' type='text'><br><br>\n";
echo "<input type='submit' value='Добавить'></form>\n";
echo "</div>\n";
echo "<div class=stat><a href='room.php'>Назад</a></div>\n";
echo "<div class=stat><a href='index.php'>Админка</a></div>\n";
echo "<div class=stat><a href='../index.php'>Прихожая</a></div>\n";
break;
case('addroom'):
$posit = mysql_query("SELECT * FROM `room`");
$position = mysql_num_rows($posit) + '1';
$name=htmlspecialchars(stripslashes(trim($_POST[name])));
$add = mysql_query ("INSERT INTO room (name,position) VALUES ('$name','$position')");
header ("Location: room.php");  exit;
break;}}
if(isset($user['level']) && $user['level']=='0'){
header ("Location: ../index.php");  exit;}
} else {header ("Location: ../index.php");  exit;}
include '../style/foot.php';
?>