Файл: minichat_by_KoT/minichat_by_KoT/forum.php
Строк: 246
<?php
##########################################
# ~ Разработка отдельных модулей ~~~~~~~ #
# ~ и написание скриптов на php (c)KoT ~ #
# ~ ICQ: 7675072 ~~~~~~~~~~~~~~~~~~~~~~~ #
# ~ Site: 4atlove.ru ~~~~~~~~~~~~~~~~~~~ #
# ~ E-mail: notefreebk.ru ~~~~~~~~~~~~~ #
##########################################
require 'sid.php';
header("Cache-Control: no-cache");
header('Content-Type:text/html; charset=UTF-8');
require 'config.php';
$link = connect_db();
list($row, $id, $ps) = check_login($link);
include 'head.php';
whorm(0, 'forum');
$go = isset($_GET['go']) ? $_GET['go'] : NULL;
switch($go) {
default:
echo $div1 . '<b>Форум</b>' . $div5;
$que = mysql_query("SELECT * FROM `forum_sections` ORDER BY `id` ASC");
echo $div3;
while ($dtm = mysql_fetch_assoc($que))
{
$f = $dtm['id'];
$f_name = $dtm['name'];
$q = mysql_query("SELECT * FROM `forum_topic` WHERE `section` = '".(int)$f."'");
$kol = mysql_num_rows($q);
echo $other . '<a href="forum.php?go=s1&f='.$f.'"><b>' . $f_name . '</b></a><b>(' . $kol . ')</b>' . $div5;
}
echo $div5;
break;
case s1:
if (!ctype_digit($_GET['f'])) {
header('Location: index.php?isset=403');
die();
}
$q = mysql_query("SELECT `name` FROM `forum_sections` WHERE `id`='".(int)$_GET['f']."'");
if (mysql_num_rows($q) == false) {
echo $bad . 'Ошибка! Раздел не найден.' . $div5;
include 'foot.php';
exit();
}
$sect1 = mysql_fetch_array($q);
$sect = $sect1['name'];
echo $div3;
echo $div1 . '<b>' . $sect . '</b>' . $div5 . '
<b>• <a href="forum.php?f='.$_GET['f'].'&go=s2">Новая тема</a></b><hr/>';
if (isset($_GET['page']) && !ctype_digit($_GET['page'])) {
header('Location: index.php?isset=403');
die();
}
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
$start = ($page - 1) * 5;
$k = mysql_result(mysql_query("SELECT count(*) FROM `forum_topic` WHERE `section` = '".(int)$_GET['f']."'"), 0);
$k = ceil($k/5);
$k = $k > 5 ? 5 : $k;
$q1 = mysql_query("SELECT * FROM `forum_topic` WHERE `section` = '".(int)$_GET['f']."' ORDER BY `time` DESC LIMIT ".abs(intval($start)).", 5");
if ($k == 0)
{
echo 'Нет созданых тем...<br/>';
}
while ($topic = mysql_fetch_assoc($q1))
{
$time = $topic['time'];
$t = $topic['id'];
$name = $topic['name'];
$close = $topic['close'];
$num = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_message` WHERE `topic` = '".(int)$t."'"), 0);
if ($close == 1)
{
echo '<img src="img/zakr.gif" alt="x"/>
<a href="forum.php?f='.$_GET['f'].'&t='.$t.'&go=s4"><b>' . $name . '</b></a> (' . $num . ')<br/>
<small>' . date('d.m-H:i', $time). '</small><br/>';
}
else
echo '<img src="img/forums.gif" alt="."/>
<a href="forum.php?f='.$_GET['f'].'&t='.$t.'&go=s4"><b>' . $name . '</b></a> (' . $num . ')<br/>
<small>' . date('d.m-H:i', $time). '</small><br/>';
}
for($i = 1; $i <= $k; $i++)
{
echo $pr=(($i == 1 || $i == $k || abs($i-$page) < 2) ? ($i == $page ? " [$i] " : ' <b><a href="forum.php?f='.$_GET['f'].'&go=s1&page='.$i.'">'.$i.'</a></b>') : (($pr == ' ... ' || $pr == '')? '' : ' ... '));
}
echo '<br/>';
echo '<hr/><a href="forum.php?f='.$_GET['f'].'&go=s1">В начало</a><br/>';
echo $div5;
break;
case s2:
$f = abs(intval($_GET['f']));
$sect = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_sections` WHERE `id` = '".(int)$f."'"));
echo $other . '
<b>Новая тема в «' . $sect['name'] . '»</b><br/>
<form action="forum.php?go=s3" method="POST">
Тема:<br/>
<input type="text" class="text" name="theme" maxlength="150" title="theme"/><br/>
<input type="hidden" name="f" value="'.$f.'">
<input type="submit" value="Добавить" class="ibutton"/>
</form>
<a href="forum.php?go=s1&f='.$f.'">Назад в «' . $sect['name'] . '»</a>' . $div5;
break;
case s3:
$f = (int)$_POST['f'];
echo '<meta http-equiv="refresh" content="1;URL=forum.php?f='.$f.'&go=s1"/>';
$nick = $row['user'];
$theme = substr($theme, 0, 300);
$theme = trim(mysql_real_escape_string(check($_POST['theme'])));
$prev = mysql_fetch_array(mysql_query("SELECT `name` FROM `forum_topic` WHERE `name`='$theme' LIMIT 1"));
if (empty($theme))
{
echo $bad . 'Вы не заполнили тему!' . $div5;
include 'foot.php';
exit();
}
else
{
if ($theme == $prev['name'])
{
echo $bad . 'Такая тема уже есть!' . $div5;
include 'foot.php';
exit();
}
else
{
$add = "INSERT INTO `forum_topic` SET
`section` = '".(int)$f."',
`login` = '".check($nick)."',
`name` = '$theme',
`close` = '0',
`time` = '".time()."'";
if (mysql_query($add))
{
echo $good . 'Тема успешно добавлена!' . $div5;
mysql_query("UPDATE `forum_sections` SET `time` = '".time()."' WHERE `id` = '".(int)$f."'");
include 'foot.php';
exit();
}
else
{
$msg = $bad . 'Произошла ошибка...' . $div5;
include 'foot.php';
exit();
}
}
}
case s4:
if (isset($_GET['f']) && !ctype_digit($_GET['f'])) {
header('Location: index.php?isset=403');
die();
}
if (isset($_GET['t']) && !ctype_digit($_GET['t'])) {
header('Location: index.php?isset=403');
die();
}
$f = (int)$_GET['f'];
$t = (int)$_GET['t'];
$sec = mysql_query("SELECT * FROM `forum_sections` WHERE `id` = '$f'");
$top = mysql_query("SELECT * FROM `forum_topic` WHERE `id` = '$t'");
if (mysql_num_rows($top) == false) {
echo $bad . 'Ошибка! Тема не найдена.' . $div5;
include 'foot.php';
exit();
}
if (mysql_num_rows($sec) == false) {
echo $bad . 'Ошибка! Раздел не найден.' . $div5;
include 'foot.php';
exit();
}
$topic = mysql_fetch_assoc($top);
$sect = mysql_fetch_assoc($sec);
if (isset($_GET['ed'])) {
echo $good . 'Тема изменена!' . $div5;
}
if (isset($_GET['otv'])) {
echo $good . 'Сообщение добавлено!' . $div5;
}
echo $div1 . '<b>' . $topic['name'] . '</b>(' . ($_GET['p'] + 1) . ' стр.)' . $div5 . $other;
if ($topic['close'] == 1)
{
echo '<hr/><img src="img/temazakr.gif" alt=""/> <b>Тема закрыта!</b><hr/>';
}
else
{
echo $div3 . '<b>• <a href="forum.php?f='.$f.'&t='.$t.'&go=s5">Ответить</a></b>' . $div5;
}
if (isset($_GET['page']) && !ctype_digit($_GET['page'])) {
header('Location: index.php?isset=403');
die();
}
$page = isset($_GET['page']) ? abs(intval($_GET['page'])) : 1;
$start = ($page - 1) * 5;
$k = mysql_result(mysql_query("SELECT count(*) FROM `forum_message` WHERE `topic` = '$t'"), 0);
$k = ceil($k/5);
$k = $k > 5 ? 5 : $k;
$q2 = mysql_query("SELECT * FROM `forum_message` WHERE `topic` = '$t' ORDER BY `id` ASC LIMIT ".abs(intval($start)).", 5");
if ($k == 0)
{
echo '<hr/>Здесь сообщений пока нет!<hr/>';
}
$pages = $start + 1;
while ($mess = mysql_fetch_assoc($q2))
{
$nick = $mess['login'];
$text = $mess['msg'];
$time = $mess['time'];
$m = $mess['id'];
$who = mysql_fetch_assoc(mysql_query("SELECT `id` FROM `users` WHERE `user` = '".check($nick)."'"));
if ($row['level'] == 2) {
$del = '<a href="forum.php?f='.$f.'&t='.$t.'&m='.$m.'&go=d1"> [X]</a>';
}
echo $div3 . $del . $pages++ . '.
<a href="forum.php?go=otvet&f='.$f.'&t='.$t.'&m='.$m.'&nk='.$who['id'].'"><b>' . col($nick) . '</b></a>
<small>' . date('(H:i)', $time) . '</small><br/>
' . $text . $div5;
}
if ($topic['close'] == 1)
{
echo '<hr/><img src="img/temazakr.gif" alt=""/> <b>Тема закрыта!</b><hr/>';
}
else
{
echo $div3 . '<b>• <a href="forum.php?f='.$f.'&t='.$t.'&go=s5">Ответить</a></b>' . $div5;
}
for($i = 1; $i <= $k; $i++)
{
echo $pr=(($i == 1 || $i == $k || abs($i-$page) < 2) ? ($i == $page ? " [$i] " : ' <b><a href="forum.php?f='.$f.'&t='.$t.'&go=s4&page='.$i.'">'.$i.'</a></b>') : (($pr == ' ... ' || $pr == '')? '' : ' ... '));
}
echo '<br/>';
echo '<a href="forum.php?go=s1&f='.$f.'">Назад в «' . $sect['name'] . '»</a><br/>';
echo $div5;
if ($row['level'] == 2) {
echo $div3;
if ($topic['close'] == 1) {
echo '<a href="forum.php?go=o2&f='.$f.'&t='.$t.'">Открыть тему</a><br/>';
}
else
{
echo '<a href="forum.php?go=o1&f='.$f.'&t='.$t.'">Закрыть тему</a><br/>';
}
echo '<a href="forum.php?go=d2&f='.$f.'&t='.$t.'">Удалить тему</a><br/>
<a href="forum.php?go=edit_them&f='.$f.'&t='.$t.'">Изменить тему</a><br/>';
}
echo $div5;
break;
case otvet:
echo $div1 . '<b>Ответ</b>' . $div5;
if (!ctype_digit($_GET['f'])) {
header('Location: index.php?isset=403');
die();
}
if (!ctype_digit($_GET['t'])) {
header('Location: index.php?isset=403');
die();
}
if (isset($_GET['nk']) && !ctype_digit($_GET['nk'])) {
header('Location: index.php?isset=403');
die();
}
$f = (int)$_GET['f'];
$t = (int)$_GET['t'];
$nk = (int)$_GET['nk'];
$topic = mysql_fetch_array(mysql_query("SELECT * FROM `forum_topic` WHERE `id`='$t'"));
if ($topic['close'] == 1)
{
echo $bad . 'Тема «' . $topic['name'] . '» закрыта!' . $div5;
include 'foot.php';
exit();
}
$sec = mysql_query("SELECT `id` FROM `forum_sections` WHERE `id` = '$f'");
$top = mysql_query("SELECT `id` FROM `forum_topic` WHERE `id` = '$t'");
if (mysql_num_rows($top) == false) {
echo $bad . 'Ошибка! Тема не найдена.' . $div5;
include 'foot.php';
exit();
}
if (mysql_num_rows($sec) == false) {
echo $bad . 'Ошибка! Раздел не найден.' . $div5;
include 'foot.php';
exit();
}
if (isset($_GET['nk']) && !user_inf($nk, 'id')) {
echo $bad . 'Ошибка!' . $div5;
include 'foot.php';
exit();
}
if (isset($_POST['ok'])) {
$msg = trim(mysql_real_escape_string(check($_POST['msg'])));
$msg = bb_code(smiles($msg));
if (empty($msg)) {
echo $bad . 'Вы не ввели сообщение!' . $div5;
} else {
$add = "INSERT INTO `forum_message` SET
`topic` = '$t',
`login` = '$row[user]',
`msg` = '$msg',
`time` = '".time()."'";
if (mysql_query($add))
{
mysql_query("UPDATE `forum_topic` SET `time` = '".time()."' WHERE `id` = '$t'");
header('Location: forum.php?go=s4&t='.$t.'&f='.$f.'&otv');
} else {
echo $bad . 'Произошла ошибка...' . $div5;
}
}
}
echo $div3 . '
<form method="POST" action="forum.php?go=otvet&f='.$f.'&t='.$t.'">
#Текст:<br/>
<textarea name="msg" cols="20" rows="4"/>[b]' . user_inf($nk, 'user') . '[/b], </textarea>
<br/>
<input type="submit" class="ibutton" name="ok" value="Ответить"/>
</form>' . $div5;
break;
case edit_them:
if (isset($_GET['f']) && !ctype_digit($_GET['f'])) {
header('Location: index.php?isset=403');
die();
}
if (isset($_GET['t']) && !ctype_digit($_GET['t'])) {
header('Location: index.php?isset=403');
die();
}
$f = (int)$_GET['f'];
$t = (int)$_GET['t'];
$them = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topic` WHERE `id` = '$t'"));
$name = trim(mysql_real_escape_string(check($_POST['name'])));
if (isset($_POST['edit_ok'])) {
if (empty($name)) {
echo $bad . 'Вы не заполнили тему!' . $div5;
} else {
$sql = "UPDATE `forum_topic` SET `name` = '$name' WHERE `id` = '$t'";
if (mysql_query($sql)) {
header('Location: forum.php?go=s4&f='.$f.'&t='.$t.'&ed');
} else {
echo $bad . 'Произошла ошибка...' . $div5;
}
}
}
echo $div1 . '<b>Редактировать тему:</b>' . $div5;
echo $div3 . '
<form method="POST" action="forum.php?go=edit_them&f='.$f.'&t='.$t.'">
<input type="text" class="text" name="name" value="' . $them['name'] . '"/>
<br/>
<input type="submit" class="ibutton" name="edit_ok" value="Изменить"/>
</form>' . $div5;
break;
case s5:
if (isset($_GET['f']) && !ctype_digit($_GET['f'])) {
header('Location: index.php?isset=403');
die();
}
if (isset($_GET['t']) && !ctype_digit($_GET['t'])) {
header('Location: index.php?isset=403');
die();
}
$f = (int)$_GET['f'];
$t = (int)$_GET['t'];
$sect = mysql_fetch_array(mysql_query("SELECT * FROM `forum_sections` WHERE `id` = '$f'"));
$topic = mysql_fetch_array(mysql_query("SELECT * FROM `forum_topic` WHERE `id` = '$t'"));
echo $other . '
<b>Ответить в «' . $sect['name'] . '»</b><br/>
<form action="forum.php?go=s6" method="POST">
#Текст:<br/>
<textarea name="msg" class="text" cols="20" rows="4"/></textarea>
<br/>
<input type="hidden" name="f" value="'.$f.'">
<input type="hidden" name="t" value="'.$t.'">
<input type="submit" value="Добавить" class="ibutton"/>
</form>
<a href="forum.php?go=s1&f='.$f.'">Назад в «' . $sect['name'] . '»</a>' . $div5;
break;
case s6:
if (isset($_GET['f']) && !ctype_digit($_GET['f'])) {
header('Location: index.php?isset=403');
die();
}
if (isset($_GET['t']) && !ctype_digit($_GET['t'])) {
header('Location: index.php?isset=403');
die();
}
$f = (int)$_POST['f'];
$t = (int)$_POST['t'];
echo '<meta http-equiv="refresh" content="1;URL=forum.php?f='.$f.'&t='.$t.'&go=s4"/>';
$topic = mysql_fetch_array(mysql_query("SELECT * FROM `forum_topic` WHERE `id`='$t'"));
if ($topic['close'] == 1)
{
echo $bad . 'Тема «' . $topic['name'] . '» закрыта!' . $div5;
include 'foot.php';
exit();
}
else
{
if (empty($_POST['msg']))
{
echo $bad . 'Пустое сообщение!' . $div5;
include 'foot.php';
exit();
}
else
{
$nick = $row['user'];
$msg = trim(mysql_real_escape_string(check($_POST['msg'])));
$msg = mb_substr($msg, 0, 600, 'UTF8');
$msg = bb_code(smiles($msg));
$prev = mysql_fetch_array(mysql_query("SELECT `msg` FROM `forum_message` WHERE `login` = '".check($nick)."' ORDER BY `id` DESC"));
if ($msg == $prev['msg'])
{
echo $bad . 'Сообщения повторяются!' . $div5;
include 'foot.php';
exit();
}
else
{
$add = "INSERT INTO `forum_message` SET
`topic` = '$t',
`login` = '".check($nick)."',
`msg` = '$msg',
`time` = '".time()."'";
if (mysql_query($add))
{
echo $good . 'Сообщение добавлено!' . $div5;
mysql_query("UPDATE `forum_topic` SET `time` = '".time()."' WHERE `id` = '$t'");
include 'foot.php';
exit();
}
else
{
echo $bad . 'Произошла ошибка...' . $div5;
include 'foot.php';
exit();
}
}
}
}
case d1:
$f = (int)$_GET['f'];
$t = (int)$_GET['t'];
echo '<meta http-equiv="refresh" content="1;URL=forum.php?f='.$f.'&t='.$t.'&go=s4"/>';
if (isset($_GET['m']) && !ctype_digit($_GET['m'])) {
header('Location: index.php?isset=403');
die();
}
if ($row['level'] != 2)
{
echo $bad . 'Ошибка!' . $div5;
include 'foot.php';
exit();
}
else
{
if (mysql_query("DELETE FROM `forum_message` WHERE `id` = '".(int)$_GET['m']."'"))
{
echo $good . 'Сообщение удалено!' . $div5;
include 'foot.php';
exit();
}
else
{
echo $bad . 'Произошла ошибка...' . $div5;
include 'foot.php';
exit();
}
break;
}
case d2:
if (!ctype_digit($_GET['t'])) {
header('Location: index.php?isset=403');
die();
}
if (!ctype_digit($_GET['f'])) {
header('Location: index.php?isset=403');
die();
}
$f = (int)$_GET['f'];
$t = (int)$_GET['t'];
echo '<meta http-equiv="refresh" content="1;URL=forum.php?f='.$f.'&go=s1"/>';
if ($row['level'] != 2)
{
echo $bad . 'Ошибка!' . $div5;
include 'foot.php';
exit();
}
else
{
if (mysql_query("DELETE FROM `forum_message` WHERE `topic` = '$t'"))
{
echo $good . 'Все сообщения удалены!' . $div5;
if (mysql_query("DELETE FROM `forum_topic` WHERE `id` = '$t'"))
{
echo $good . 'Тема удалена!' . $div5;
include 'foot.php';
exit();
}
else
{
echo $bad . 'Ошибка удаления темы!' . $div5;
include 'foot.php';
exit();
}
}
else
{
echo $bad . 'Ошибка!' . $div5;
include 'foot.php';
exit();
}
}
case o1:
if (!ctype_digit($_GET['t'])) {
header('Location: index.php?isset=403');
die();
}
if (!ctype_digit($_GET['f'])) {
header('Location: index.php?isset=403');
die();
}
$f = (int)$_GET['f'];
$t = (int)$_GET['t'];
if (mysql_query("UPDATE `forum_topic` SET `close` = '1' WHERE `id` = '$t'"))
{
$msg = $good . 'Тема закрыта!' . $div5;
}
else
{
$msg = $bad . 'Произошла ошибка...' . $div5;
}
echo '<meta http-equiv="refresh" content="1;URL=forum.php?f='.$f.'&go=s1"/>';
echo $msg;
break;
case bb:
echo $div1 . '<b>Справка по тегам</b>' . $div5;
echo $div3 . '
Вы можете выражать свой текст следующими тегами:<br/><br/>
[b]<b>Жирный шрифт</b>[/b]<br/>
[i]<i>Наклонный шрифт</i>[/i]<br/>
[u]<u>Подчеркнутый шрифт</u>[/u]<br/>
[q]<div class="quote">Для вставки цитат</div>[/q]<br/>
[small]<small>Мелкий шрифт</small>[/small]<br/>
[del]<del>Зачеркнутый шрифт</del>[/del]<br/>
[red]<font color="red">Красный цвет</font>[/red]<br/>
[green]<font color="green">Зеленый цвет</font>[/green]<br/>
[blue]<font color="blue">Синий цвет</font>[/blue]<br/>
[yellow]<font color="yellow">Желтый цвет</font>[/yellow]<br/><br/>
[code]'.bb_code("[code]<? echo 'Для вставки php-кода'; ?>[/code]").'[/code]<br/><br/>
[url=http://адрес_cсылки] Название [/url]' . $div5;
break;
case o2:
if (!ctype_digit($_GET['t'])) {
header('Location: index.php?isset=403');
die();
}
if (!ctype_digit($_GET['f'])) {
header('Location: index.php?isset=403');
die();
}
$f = (int)$_GET['f'];
$t = (int)$_GET['t'];
if (mysql_query("UPDATE `forum_topic` SET `close` = '0' WHERE `id` = '$t'"))
{
$msg = $good . 'Тема открыта!' . $div5;
}
else
{
$msg = $bad . 'Произошла ошибка...' . $div5;
}
echo '<meta http-equiv="refresh" content="1;URL=forum.php?f='.$f.'&go=s1"/>';
echo $msg;
break;
}
echo $other . '<a href="forum.php?go=bb">BB-code</a>' . $div5;
echo $div3;
if (isset($_GET['go'])) {
echo '<a href="forum.php?'.$ref.'"><b>В форумы</b></a><br/>';
}
echo '<a href="menu.php?'.$ref.'"><b>В меню</b></a>' . $div5;
include 'foot.php';
?>