Файл: forum.php
Строк: 702
<?php
define('_IN_JOHNCMS', 1);
$rootpath = __DIR__ .'/';
$headmod = "miniForum";
require_once('incfiles/core.php');
#########################################################################################################
# Вспомогателные функции
#########################################################################################################
function notify($msg = false, $type = true) {
if ($msg) {
if ($type === true) {
$_SESSION['err_msg'] .= $msg .'<br>';
} elseif ($type === false) {
$_SESSION['succ_msg'] .= $msg .'<br>';
}
}elseif (isset($_SESSION['err_msg'])) {
echo '<div class="gmenu">'. $_SESSION['err_msg'] .'</div>';
unset($_SESSION['err_msg']);
} elseif (isset($_SESSION['succ_msg'])) {
echo '<div class="rmenu">'. $_SESSION['succ_msg'] .'</div>';
unset($_SESSION['succ_msg']);
}
}
function out($text, $max = 25) {
return str_replace('<br />', "rn", tags(antilink(nl2br(mb_substr($text, 0, $max)))));
}
$query = mysql_query('SELECT * FROM `mini_forum` WHERE `type` = "cat" ');
if (!isset($_GET['start'])) {
$_GET['start'] = 0;
}
########################################################################################################
# Темы
########################################################################################################
if (isset($_POST['save_edit_post'])) {
if (!$user_id) {
header("Location: /");
echo display_errors('Доступ запрещен!');
require_once('incfiles/end.php');
exit;
}
$text = mysql_escape_string(htmlspecialchars(mb_substr($_POST['topic_message_edit'], 0, 5000)));
if (mb_strlen(trim($text)) < 3) {
notify('Сообщение должно быть от 3 до 5000 символов!', false);
header('Location: ?edit_post='. (int)$_POST['edit_post_id']);
exit;
}
mysql_query('UPDATE `mini_forum` SET `text` = "'. $text .'" WHERE `id` = "'. (int)$_POST['edit_post_id'].'" ');
notify('Сообщение успешно изменено!');
header('Location: ?view_topic='. (int)$_POST['edit_post_tid']);
exit;
exit;
}
// Редактированние поста
if (isset($_GET['edit_post'])) {
if (!$user_id) {
header("Location: /");
echo display_errors('Доступ запрещен!');
require_once('incfiles/end.php');
exit;
}
$editQuery = mysql_query('SELECT `id`, `text`, `last_user_id`, `tid` FROM `mini_forum` WHERE `id` = "'. (int)$_GET['edit_post'] .'"');
if (mysql_num_rows($editQuery) !== 1) {
notify('Данного поста не существует!', false);
header('Location: ?view_topic='. (int)$_GET['edit_post']);
exit;
} else {
$editPost = mysql_fetch_array($editQuery);
if ( ((int)$editPost['last_user_id'] !== (int)$user_id) || ($rights < 7) ) {
if (!$user_id) {
header("Location: /");
echo display_errors('Доступ запрещен!');
require_once('incfiles/end.php');
exit;
}
}
$textl = 'Форум | Редактированние поста!';
require_once('incfiles/head.php');
notify();
echo '<div class="gmenu">
<form action="?" method="post">
Редактируемое сообщение:<br>
<textarea name="topic_message_edit">'. nl2br(htmlspecialchars($editPost['text'])) .'</textarea><br>
<input type="hidden" name="edit_post_id" value="'. $editPost['id'] .'">
<input type="hidden" name="edit_post_tid" value="'. $editPost['tid'] .'">
<input type="submit" name="save_edit_post" value="Отправить!">
</form>
</div>
<div class="phdr"><a href="?view_topic='. $editPost['tid'] .'">В тему</a></div>';
require_once('incfiles/end.php');
}
exit;
}
// ПРОСМОТР ТЕМЫ
if (isset($_GET['delet_post'])) {
if (isset($_POST['delet_topic_posts'])) {
$deletTopic = false;
foreach((array)$_POST['delet_posts'] as $postId) {
$deletThemeQuery = mysql_query('SELECT `id`, `title` FROM `mini_forum` WHERE `type` = "theme" AND `tid` = "'. (int)$postId .'" ');
if (mysql_num_rows($deletThemeQuery) === 1) {
$deletTopicArr = mysql_fetch_array($deletThemeQuery);
$deletTopic = $deletTopicArr['title'];
$del_cates = mysql_query('SELECT `id` FROM `mini_forum` WHERE `tid` = "'.(int)$deletTopicArr['id'].'" AND `type` = "msg"');
while ($del_con = mysql_fetch_array($del_cates)) {
mysql_query('DELETE FROM `mini_forum` WHERE `id` = "'. $del_con['id'] .'" AND `type` = "msg" ');
}
mysql_query('DELETE FROM `mini_forum` WHERE `id` = "'. $deletTopicArr['id'] .'" ');
break;
}
mysql_query('DELETE FROM `mini_forum` WHERE `id` = "'. $postId .'" ');
}
if ($deletTopic === false) {
notify('Удалено '. count($_POST['delet_posts']) .' сообщений!');
header('Location: ?view_topic='. $_GET['delet_post']);
exit;
} else {
notify('Тема "'. $deletTopic .'" успешно удалена!');
header('Location: ?');
exit;
}
}
header('Location: ?');
exit;
}
if (isset($_GET['view_topic'])) {
$topic = mysql_query('SELECT `id`, `title` FROM `mini_forum` WHERE `type` = "theme" AND `id` = "'. (int)$_GET['view_topic'] .'" ');
if (mysql_num_rows($topic) !== 1) {
notify('Данной темы не существует!', false);
header('Location: ?');
exit;
}
$formValue = "";
$topicQueryCount = mysql_num_rows(mysql_query('SELECT * FROM `mini_forum` WHERE `type` = "msg" AND `tid` = "'. (int)$_GET['view_topic'] .'" ORDER BY `id` ASC '));
$topicQuery = mysql_query('SELECT * FROM `mini_forum`
WHERE `type` = "msg" AND `tid` = "'. (int)$_GET['view_topic'] .'" ORDER BY `id` ASC LIMIT '.(int)$_GET['start'] .', '. ((int)$_GET['start'] + 10) .' ');
$topicCategory = mysql_fetch_array(mysql_query('SELECT * FROM `mini_forum` WHERE `type` = "cat" AND `id` = "'.
mysql_result(mysql_query('SELECT `cid` FROM `mini_forum` WHERE `id` = "'. (int)$_GET['view_topic'] .'"'), 0) .'" '));
$topicName = mysql_fetch_array($topic);
//ЗАПИСЬ ЦИТАТЫ В БАЗУ
if (isset($_POST['add_topic_message_post'])) {
$file_new_name = 0;
$text = mysql_escape_string(htmlspecialchars(mb_substr($_POST['topic_message'], 0, 5000)));
if (mb_strlen(trim($text)) < 3) {
notify('Сообщение должно быть от 3 до 5000 символов!', false);
header('Location: ?view_topic='. (int)$_GET['view_topic']);
exit;
}
$topicQueryQuote = mysql_query('SELECT * FROM `mini_forum` WHERE `type` = "msg" AND `text` = "'. $text .'" AND `tid` = "'. (int)$_GET['view_topic'] .'" ');
if (mysql_num_rows($topicQueryQuote) !== 0) {
notify('Такое сообщение уже есть!', false);
header('Location: ?view_topic='. (int)$_GET['view_topic']);
exit;
}
if (isset($_FILES['attach']) && $_FILES['attach']['name'] !== '') {
$file = $_FILES['attach'];
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$file_error = $file['error'];
$file_size = $file['size'];
$file_ext = pathinfo($file_name, PATHINFO_EXTENSION);
$allowed = array('jpg', 'jpeg', 'png', 'gif', 'JPG', 'JPEG', 'PNG', 'GIF');
if ( ! in_array($file_ext, $allowed)) {
notify('Запрещенное расширение файла!', false);
header('Location: ?view_topic='. (int)$_GET['view_topic']);
exit;
}
if ($file_error !== 0) {
notify('Ошибка загрузки файла!', false);
header('Location: ?view_topic='. (int)$_GET['view_topic']);
exit;
}
if ((round($file_size / 1048576 * 100) / 100) > 5) {
notify('Файл слишком большой!', false);
header('Location: ?view_topic='. (int)$_GET['view_topic']);
exit;
}
$file_new_name = uniqid('', true) . '.' . $file_ext;
$file_descination = __DIR__ .'/files/' . $file_new_name;
if ( ! move_uploaded_file($file_tmp, $file_descination)) {
notify('Ошибка загрузки файла на сервер!', false);
header('Location: ?view_topic='. (int)$_GET['view_topic']);
exit;
}
}
if (mb_substr_count($text, '[c]') === 1) {
$quote = 1;
} else {
$quote = 0;
}
mysql_query('INSERT INTO `mini_forum` (`type`, `text`, `cid`, `tid`, `quote`, `create_time`, `last_user_id`, `attach`) VALUES
("msg", "'. $text .'", "'. $topicCategory['id'] .'", "'. (int)$_GET['view_topic'] .'", "'. $quote .'", "'. time() .'", "'. $user_id .'", "'. $file_new_name .'")');
mysql_query('UPDATE `mini_forum` SET `last_time` = "'. time() .'", `last_user_id` = "'. $user_id .'" WHERE `id` = "'. (int)$_GET['view_topic'] .' "');
notify('Сообщение успешно добавлено!');
header('Location: ?view_topic='. (int)$_GET['view_topic']);
exit;
}
$textl = 'Форум | '. $topicCategory['title'] .' | '. $topicName['title'];
require_once('incfiles/head.php');
?>
<style type="text/css">
.showPhoto {
width: 0;
height: 0;
position: fixed;
overflow: hidden;
left: 0;
top: 0;
z-index: 9999;
text-align: center;
background: rgba(0,0,0,0.7);
}
.showPhoto img {
opacity: 0;
padding: 10px;
background: #ffffff;
width: 50%;
height: auto;
margin: auto;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
-webkit-box-shadow: 0px 0px 15px #444;
-moz-box-shadow: 0px 0px 15px #444;
box-shadow: 0px 0px 15px #444;
-moz-transition: opacity .25s ease-in-out;
-webkit-transition: opacity .25s ease-in-out;
transition: opacity .25s ease-in-out;
}
.showPhoto:target {background-color: transparent;width: auto;height: auto;bottom: 0;right: 0;}
.showPhoto:target img {opacity: 1;}
.links:hover {
cursor: hover;
}
</style>
<script type="text/javascript">
function on(n) {
eval("document.all.text"+n+".style.display='block';");
eval("document.all.ontext"+n+".style.display='none';");
}
function show(e) {
var width = 520; height = 390;
var wnd = window.open(e.href, '_blank', 'width='+width+', height='+height+',toolbar=no,menubar=no,scrollbars=no,status=no,resizable=yes');
if (wnd) { wnd.moveTo((screen.width - width) / 2, (screen.height - height) / 3); wnd.focus(); }
return false;
}
function insert(unit) {
var id ='text';
var object = document.getElementById(id);
object.focus();
var ss = object.scrollTop;
sel1 = object.value.substr(0, object.selectionStart);
sel2 = object.value.substr(object.selectionEnd);
sel = object.value.substr(object.selectionStart, object.selectionEnd - object.selectionStart);
object.value = sel1 + sel + unit + sel2;
object.selectionStart = sel1.length + unit.length;
object.selectionEnd = object.selectionStart + sel.length;
object.scrollTop = ss;
return false;
}
function show_hide(elem) {
obj = document.getElementById(elem);
if( obj.style.display == "none" ) {
obj.style.display = "block";
} else {
obj.style.display = "none";
}
}
</script>
<?php
notify();
echo '<div class="phdr"><a name="up" id="up"></a>
<a href="#down"><img src="../theme/' . $set_user['skin'] . '/images/down.png" alt="Вниз" width="20" height="10" border="0"/></a>
<a href="/forum.php">Форум </a> >>
<a href="/forum.php?view_cat='. $topicCategory['id'] .'">'.$topicCategory['title'] .' </a> >> <b>'. $topicName['title'] .'</b></div>';
$topicAttachMsg = mysql_fetch_array(mysql_query('SELECT * FROM `mini_forum` WHERE `type` = "msg" AND `id` = "'.
mysql_result(mysql_query('SELECT `tid` FROM `mini_forum` WHERE `id` = "'. (int)$_GET['view_topic'] .'"'), 0) .'" '));
$topicAttachMsgAuthor = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "'. $topicAttachMsg['last_user_id'] .'" '));
if ($rights >= 7) {
echo '<form action="?delet_post='. (int)$_GET['view_topic'] .'" method="post">';
}
echo '<div class="gmenu"><table cellpadding="0" cellspacing="0"><tr><td>';
if (file_exists('files/photo/' . (int)$topicAttachMsgAuthor['id'] .'_small.png')) {
echo '<img src="../files/photo/' . (int)$topicAttachMsgAuthor['id'] .'_small.png" width="50" height="50" alt="ava" /> ';
} elseif (file_exists('files/photo/' . (int)$topicAttachMsgAuthor['id'] .'_small.jpg')) {
echo '<img src="../files/photo/' . (int)$topicAttachMsgAuthor['id'] .'_small.jpg" width="50" height="50" alt="ava" /> ';
} elseif (file_exists('files/photo/' . (int)$topicAttachMsgAuthor['id'] .'_small.jpeg')) {
echo '<img src="../files/photo/' . (int)$topicAttachMsgAuthor['id'] .'_small.jpeg" width="50" height="50" alt="ava" /> ';
} elseif (file_exists('files/photo/' . (int)$topicAttachMsgAuthor['id'] .'_small.gif')) {
echo '<img src="../files/photo/' . (int)$topicAttachMsgAuthor['id'] .'_small.gif" width="50" height="50" alt="ava" /> ';
} else {
echo '<img src="../images/empty.png" width="50" height="50" alt="ava" /> ';
}
echo '</td><td>';
if ($topicAttachMsgAuthor['sex']) {
echo '<img src="../theme/' . $set['skindef'] . '/images/' . ($topicAttachMsgAuthor['sex'] == 'm' ? 'm' : 'f') .
($topicAttachMsgAuthor['datereg'] > $realtime - 86400 ? '_new.png" width="14"' : '.png" width="16"') . ' height="16"/> ';
} else {
echo '<img src="../images/del.png" width="10" height="10" /> ';
}
echo '<a href="/str/anketa.php?id=' . $topicAttachMsgAuthor['id'] . '"><b>'.$topicAttachMsgAuthor['imname'].' '.$topicAttachMsgAuthor['name'].'</b></a>'.
($realtime > $topicAttachMsgAuthor['lastdate'] + 300 ? '<span class="red"> [Off]</span>' : '<span class="green"> [ON]</span>') .'
<br><span class="gray">(' . date("d.m.Y / H:i", $topicAttachMsg['create_time'] + $set_user['sdvig'] * 3600) . ')</span><br/>
</td></tr></table>
'. out($topicAttachMsg['text'], 500) ;
if ($user_id) {
echo '<div class="sub">';
if ($rights >=7) {
echo '<font color="red">Удаляя первый пост вы удаляете тему!</font><br>
<input type="checkbox" name="delet_posts[]" value="'. $topicAttachMsg['id'] .' " /> ';
}
echo '[ <a onclick="javascript:insert('[b]'.$topicAttachMsgAuthor['imname'].' '.$topicAttachMsgAuthor['name'].', [/b]n');">Ответить</a>
'. (((int)$topicMsg['quote'] !== 1) ?
'| <a onclick="javascript:insert('[c][b]'.$topicMsgAuthor['imname'].' '.$topicAttachMsgAuthor['name'].',[/b] '. trim($topicAttachMsg['text'], "n") .' [/c]n');" >Цитировать</a> ' : '' ) .'
'. (( ($rights >= 7) || ((int)$user_id === (int)$topicMsg['last_user_id']) ) ?
'| <a href="?edit_post='. $topicMsg['id'] .'"><font color ="green">Изменить</font></a> ' : '') .' ]</div>';
}
echo '</div>';
if ($topicQueryCount > 1) {
while($topicMsg = mysql_fetch_array($topicQuery)) {
if ($topicMsg['id'] === $topicAttachMsg['id']) {
continue;
}
$topicMsgAuthor = mysql_fetch_array(mysql_query('SELECT * FROM `users` WHERE `id` = "'. $topicMsg['last_user_id'] .'" '));
if ($div === 'bmenu') {
$div = 'menu';
} elseif ($div === 'menu') {
$div = 'bmenu';
} else {
$div = 'menu';
}
echo '<div class="'.$div.'"><table cellpadding="0" cellspacing="0"><tr><td>';
if (file_exists('files/photo/' . (int)$topicMsgAuthor['last_user_id'] .'_small.png')) {
echo '<img src="../files/photo/' . (int)$topicMsgAuthor['id'] .'_small.png" width="50" height="50" alt="ava" /> ';
} elseif (file_exists('files/photo/' . (int)$topicMsgAuthor['id'].'_small.jpg')) {
echo '<img src="../files/photo/' . (int)$topicMsgAuthor['id'] .'_small.jpg" width="50" height="50" alt="ava" /> ';
} elseif (file_exists('files/photo/' . (int)$topicMsgAuthor['id'] .'_small.jpeg')) {
echo '<img src="../files/photo/' . (int)$topicMsgAuthor['id'] .'_small.jpeg" width="50" height="50" alt="ava" /> ';
} elseif (file_exists('files/photo/' . (int)$topicMsgAuthor['id'] .'_small.gif')) {
echo '<img src="../files/photo/' . (int)$topicMsgAuthor['id'] .'_small.gif" width="50" height="50" alt="ava" /> ';
} else {
echo '<img src="../images/empty.png" width="50" height="50" alt="ava" /> ';
}
echo '</td> <td>';
if ($topicMsgAuthor['sex']) {
echo '<img src="../theme/' . $set['skindef'] . '/images/' . ($topicMsgAuthor['sex'] == 'm' ? 'm' : 'f') .
($topicMsgAuthor['datereg'] > $realtime - 86400 ? '_new.png" width="14"' : '.png" width="16"') . ' height="16"/> ';
} else {
echo '<img src="../images/del.png" width="10" height="10" /> ';
}
echo '<a href="/str/anketa.php?id=' . $topicMsgAuthor['id'] . '"><b>'.$topicMsgAuthor['imname'].' '.$topicMsgAuthor['name'].'</b></a>'.
($realtime > $topicMsgAuthor['lastdate'] + 300 ? '<span class="red"> [Off]</span>' : '<span class="green"> [ON]</span>') .'
<br><span class="gray">(' . date("d.m.Y / H:i", $topicMsg['create_time'] + $set_user['sdvig'] * 3600) . ')</span><br/>
</td></tr></table>';
if ((int)$topicMsg['attach'] !== 0) {
echo '<p align="center"><a href="#photo'. $topicMsg['attach'] .'">
<img src="../files/'. $topicMsg['attach'] .'" class="photo" title="" alt="" style="max-width: 200px;max-height: 200px;"/>
</a><a href="#close" id="photo'. $topicMsg['attach'] .'" class="showPhoto"><img src="../files/'. $topicMsg['attach'] .'"></a></p>';
}
echo out($topicMsg['text'], 5000) ;
if ($user_id) {
echo '<div class="sub">';
if ($rights >=7) {
echo '<input type="checkbox" name="delet_posts[]" value="'. $topicMsg['id'] .' " /> ';
}
echo '[ <a onclick="javascript:insert('[b]'.$topicMsgAuthor['imname'].' '.$topicMsgAuthor['name'].', [/b]n');">Ответить</a>
'. (((int)$topicMsg['quote'] !== 1) ?
'| <a onclick="javascript:insert('[c][b]'.$topicMsgAuthor['imname'].' '.$topicMsgAuthor['name'].',[/b] '.
strtr($topicMsg['text'], array("r" => "", "n" => "" ) ) .' [/c]n');">Цитировать</a> ' : '' ) .'
'. (( ($rights >= 7) || ((int)$user_id === (int)$topicMsg['last_user_id']) ) ?
'| <a href="?edit_post='. $topicMsg['id'] .'"><font color ="green">Изменить</font></a> ' : '') .' ]</div>';
}
echo '</div>';
}
} else {
echo '<div class="rmenu">Ответов пока нет :(</div>';
}
if ($rights >= 7) {
echo '<div class="phdr"><input type="submit" name="delet_topic_posts" value="Удалить!"></form></div>';
}
if ($topicQueryCount > 10) {
echo '<p>'. pagenav('?view_topic='. (int)$_GET['view_topic'] .'&', (int)$_GET['start'], $topicQueryCount, 10) .'</p>';
}
if ($user_id) {
echo '<div class="gmenu">
<form align="center" action="?view_topic='. (int)$_GET['view_topic'] .'&start='. (int)$_GET['start'] .'" method="post" enctype="multipart/form-data">
Ваше сообщение:<br>
<textarea id="text" rows="5" name="topic_message"></textarea><br>
<span id="text011" style="display: none;"><small>Форматы: jpg, jpeg, gif, png</small><br><input type="file" name="attach"/></span>
<span id="ontext011" style="display: inline;"><a href="javascript:on('011');">Прикрепить</a></span>
<input type="submit" name="add_topic_message_post" value="Отправить!">
</form>
</div>';
}
echo '<div class="phdr"><a name="down" id="down"></a>
<a href="#up"><img src="../theme/default/images/up.png" alt="Наверх" width="20" height="10" border="0"/></a>
Всего сообщений: '. $topicQueryCount .'</div>';
require_once('incfiles/end.php');
exit;
}
//ДОБАВЛЕНИЕ ТОПИКА В БАЗУ
if (isset($_POST['add_topic_post'])) {
if (!$user_id) {
header("Location: /");
echo display_errors('Доступ запрещен!');
require_once('incfiles/end.php');
exit;
}
$name = mysql_escape_string(htmlspecialchars(mb_substr($_POST['topic_name'], 0, 25)));
$text = mysql_escape_string(htmlspecialchars(mb_substr($_POST['topic_text'], 0, 500)));
if (mb_strlen(trim($name)) < 3) {
notify('Название темы должно быть от 3 до 25 символов!', false);
header('Location: ?add_topic');
exit;
}
if (mb_strlen(trim($text)) < 3) {
notify('Сообщение должно быть от 3 до 5000 символов!', false);
header('Location: ?add_topic');
exit;
}
$cid = (int)$_POST['topic_id'];
$query_top = mysql_query('SELECT * FROM `mini_forum` WHERE `type` = "theme" AND `title` = "'. $name .'" AND `cid` = "'. $cid .'" ');
if (mysql_num_rows($query_top) !== 0) {
notify('Такая тема уже существует!', false);
header('Location: ?add_topic');
exit;
} else {
mysql_query('INSERT INTO `mini_forum` SET `title` = "'. $name .'", `type` = "theme", `last_time` = "'. time() .'", `last_user_id` = "'. $user_id .'", `cid` = "'. $cid .'" ');
$id = mysql_insert_id();
mysql_query('INSERT INTO `mini_forum` (`type`, `title`, `text`, `cid`, `tid`, `create_time`, `last_user_id`) VALUES
("msg", "'. $name .'", "'. $text .'", "'. $cid .'", "'. $id .'", "'. time() .'", "'. $user_id .'")');
$messageLastId = mysql_insert_id();
mysql_query('UPDATE `mini_forum` SET `tid` = "'. $messageLastId .'" WHERE `id` = "'. $id .' "');
notify('Тема успешно созданна!');
header('Location: ?view_topic='. $id);
exit;
}
exit;
}
//ДОБАВЛЕНИЕ ТОПИКА
if (isset($_GET['add_topic'])) {
$textl = 'Форум | Добавление темы';
require_once('incfiles/head.php');
if (!$user_id) {
header("Location: /");
echo display_errors('Доступ запрещен!');
require_once('incfiles/end.php');
exit;
}
notify();
echo '<div class="phdr"><b><a href="/forum.php">Форум</a> >> Добавление темы</b></div>
<div class="list1"><form action="?" method="post">
Выберите категорию:<br>
<select name="topic_id">';
$query = mysql_query('SELECT * FROM `mini_forum` WHERE `type` = "cat" ');
while ($catt = mysql_fetch_array($query)) {
echo '<option value="'. $catt['id'] .'" '. (isset($_GET['kat_id']) && $_GET['kat_id'] === $catt['id'] ? 'selected="selected"' : '') .'>'.$catt['title'].'</option>';
}
echo ' </select><br>
Название темы (макс 250):<br>
<input type="text" name="topic_name"><br>
Сообщение (макс 5000):<br>
<textarea name="topic_text">'. $formValue .'</textarea><br>
<input type="submit" name="add_topic_post" value="Создать!">
</form></div>
';
require_once('incfiles/end.php');
exit;
}
#####################################################################################################
# УПРАВЛЕНИЕ КАТЕГОРИЯМИ
####################################################################################################
// УДАЛЕНИЕ КАТЕГОРИИ
if (isset($_GET['delet_kat'])) {
if (!$user_id && $rights < 7) {
header("Location: /");
echo display_errors('Доступ запрещен!');
require_once('incfiles/end.php');
exit;
}
$query_cat = mysql_query('SELECT * FROM `mini_forum` WHERE `type` = "cat" AND `id = "'. (int)$_GET['delet_kat'] .'" ');
if (mysql_num_rows($query_cat) === 0) {
notify('Категории не существует!', false);
header('Location: ?cat_admin');
exit;
} else {
$del_cates = mysql_query('SELECT `id` FROM `mini_forum` WHERE `cid` = "'.(int)$_GET['delet_kat'].'"');
while ($del_con = mysql_fetch_array($del_cates)) {
mysql_query('DELETE FROM `mini_forum` WHERE `id` = "'. $del_con['id'].'" ');
}
mysql_query('DELETE FROM `mini_forum` WHERE `id` = "'. (int)$_GET['delet_kat'] .'"');
mysql_query("OPTIMIZE TABLE `mini_forum` ");
notify('Категория успешно удалена!');
header('Location: ?cat_admin');
exit;
}
exit;
}
//ИЗМЕНЕНИЕ КАТЕГОРИИ
if (isset($_POST['edit_cat_post']) && isset($_POST['cat_name'])) {
if (!$user_id && $rights < 7) {
header("Location: /");
echo display_errors('Доступ запрещен!');
require_once('incfiles/end.php');
exit;
}
$name = mysql_escape_string(htmlspecialchars($_POST['cat_name']));
$query_cat = mysql_query('SELECT `id`, `title` FROM `mini_forum` WHERE `type` = "cat" AND `id` = "'. (int)$_POST['cat_id'] .'" ');
if (mysql_num_rows($query_cat) === 0) {
notify('Категории не существует!', false);
header('Location: ?cat_admin');
exit;
} elseif (mysql_num_rows(mysql_query('SELECT `id`, `title` FROM `mini_forum` WHERE `type` = "cat" AND `title` = "'. $name .'" ')) === 1) {
notify('Категория уже существует!', false);
header('Location: ?cat_admin');
exit;
} else {
$categoryEditArr = mysql_fetch_array($query_cat);
mysql_query('UPDATE `mini_forum` SET `title` = "'. $name .'" WHERE `id` = "'. $categoryEditArr['id'] .'" ');
notify('Категория успешно изменена!');
header('Location: ?cat_admin');
exit;
}
}
// ДОБАВЛЕНИЕ КАТЕГОРИИ
if (isset($_POST['add_cat_post']) && isset($_POST['cat_name'])) {
if (!$user_id && $rights < 7) {
header("Location: /");
echo display_errors('Доступ запрещен!');
require_once('incfiles/end.php');
exit;
}
$name = mysql_escape_string(htmlspecialchars($_POST['cat_name']));
$query_cat = mysql_query('SELECT * FROM `mini_forum` WHERE `type` = "cat" AND `title` = "'. $name .'" ');
if (mysql_num_rows($query_cat) !== 0) {
notify('Категория уже существует!', false);
header('Location: ?cat_admin');
exit;
} else {
mysql_query('INSERT INTO `mini_forum` SET `title` = "'. $name .'", `type` = "cat" ');
notify('Категория успешно добавленна!');
header('Location: ?cat_admin');
exit;
}
}
// АДМИНКА КАТЕГОРИЙ
if (isset($_GET['cat_admin'])) {
$adminQuery = mysql_query('SELECT * FROM `mini_forum` WHERE `type` = "cat" ');
if (!$user_id && $rights < 7) {
header("Location: /");
echo display_errors('Доступ запрещен!');
require_once('incfiles/end.php');
exit;
}
if (isset($_GET['edit_kat'])) {
$catQuery = mysql_query(' SELECT `title` FROM `mini_forum` WHERE `type` = "cat" AND `id` = "'. (int)$_GET['edit_kat'] .'" ');
if (mysql_num_rows($catQuery) !== 1) {
notify('Категория не найдена!', false);
header('Location: ?cat_admin');
exit;
}
}
$textl = 'Форум | Управление категориями';
require_once('incfiles/head.php');
notify();
if (isset($_GET['edit_kat'])) {
echo '<div class="phdr"><b><a href="/forum.php">Форум</a> >> Управление категориями</b></div>
<div class="list1"><form action="?" method="post">
Название категории (макс 250):<br>
<input type="text" name="cat_name" value=" '.
out(mysql_result($catQuery, 0)) .' ">
<input type="hidden" name="cat_id" value="'. (int)$_GET['edit_kat'] .'">
<input type="submit" name="edit_cat_post" value="Изменить!">
</form></div>
';
} else {
echo '<div class="phdr"><b><a href="/forum.php">Форум</a> >> Управление категориями</b></div>
<div class="list1"><form action="?" method="post">
Название категории (макс 250):<br>
<input type="text" name="cat_name">
<input type="submit" name="add_cat_post" value="Создать!">
</form></div>
';
}
if (mysql_num_rows($adminQuery) === 0) {
echo '<div class="rmenu">Категорий пока нет!</div>';
} else {
while ($adminCat = mysql_fetch_array($query)) {
if ($div === 'bmenu') {
$div = 'menu';
} elseif ($div === 'menu') {
$div = 'bmenu';
} else {
$div = 'menu';
}
echo '<div class="'. $div .'">
<b>'. out($adminCat['title']) .'</b>
<div class="sub">Тем: '. mysql_num_rows(mysql_query('SELECT `id` FROM `mini_forum` WHERE `cid` = "'. $adminCat['id'] .'"AND `type` = "theme"')) .'
Сообщений: '. mysql_num_rows(mysql_query('SELECT `id` FROM `mini_forum` WHERE `cid` = "'. $adminCat['id'] .'"AND `type` = "msg"')) .'
<a href="?cat_admin&edit_kat='. $adminCat['id'] .'"><font color="green">Изменить</font></a>
<a href="?delet_kat='. $adminCat['id'] .'"><font color="red">Удалить</font></a></div>
</div>';
}
}
require_once('incfiles/end.php');
exit;
}
if (isset($_GET['who'])) {
$textl = 'Форум | Кто в форуме';
require_once('incfiles/head.php');
echo '<div class="phdr"><a href="?">Форум</a> >> Кто в форуме</div>';
$who = mysql_query('SELECT * FROM `users` WHERE `place` = "'. $headmod .'" ');
$whoCount = mysql_num_rows($who);
if ($homeCount === 0) {
echo '<div class="rmenu">Никого нет!</div>';
} else {
while ($topicMsgAuthor = mysql_fetch_array($who)) {
if ($div === 'bmenu') {
$div = 'menu';
} elseif ($div === 'menu') {
$div = 'bmenu';
} else {
$div = 'menu';
}
echo '<div class="'.$div.'"><table cellpadding="0" cellspacing="0"><tr><td>';
if (file_exists('files/photo/' . (int)$topicMsgAuthor['id'] .'_small.png')) {
echo '<img src="../files/photo/' . (int)$topicMsgAuthor['id'] .'_small.png" width="50" height="50" alt="ava" /> ';
} elseif (file_exists('files/photo/' . (int)$topicMsgAuthor['id'].'_small.jpg')) {
echo '<img src="../files/photo/' . (int)$topicMsgAuthor['id'] .'_small.jpg" width="50" height="50" alt="ava" /> ';
} elseif (file_exists('files/photo/' . (int)$topicMsgAuthor['id'] .'_small.jpeg')) {
echo '<img src="../files/photo/' . (int)$topicMsgAuthor['id'] .'_small.jpeg" width="50" height="50" alt="ava" /> ';
} elseif (file_exists('files/photo/' . (int)$topicMsgAuthor['id'] .'_small.gif')) {
echo '<img src="../files/photo/' . (int)$topicMsgAuthor['id'] .'_small.gif" width="50" height="50" alt="ava" /> ';
} else {
echo '<img src="../images/empty.png" width="50" height="50" alt="ava" /> ';
}
echo '</td> <td>';
if ($topicMsgAuthor['sex']) {
echo '<img src="../theme/' . $set['skindef'] . '/images/' . ($topicMsgAuthor['sex'] == 'm' ? 'm' : 'f') .
($topicMsgAuthor['datereg'] > $realtime - 86400 ? '_new.png" width="14"' : '.png" width="16"') . ' height="16"/> ';
} else {
echo '<img src="../images/del.png" width="10" height="10" /> ';
}
echo '<a href="/str/anketa.php?id=' . $topicMsgAuthor['id'] . '"><b>'.$topicMsgAuthor['imname'].' '.$topicMsgAuthor['name'].'</b></a>'.
($realtime > $topicMsgAuthor['lastdate'] + 300 ? '<span class="red"> [Off]</span>' : '<span class="green"> [ON]</span>') .'
</td></tr></table></div>';
}
}
if ($whoCount > 10) {
echo '<p>'. pagenav('?view_topic='. (int)$_GET['view_topic'] .'&', (int)$_GET['start'], $whoCount, 10) .'</p>';
}
require_once('incfiles/end.php');
exit;
}
#####################################################################################################
# ФОРУМ ГЛАВНАЯ
#####################################################################################################
if (isset($_GET['view_cat'])) {
$homeCatQuery = mysql_query('SELECT `title` FROM `mini_forum` WHERE `id` = "'. (int)$_GET['view_cat'] .'" ');
if (mysql_num_rows($homeCatQuery) !== 1) {
notify('Категория не найдена!', false);
header('Location: ?');
exit;
}
$textl = ' Форум | ' . mysql_result($homeCatQuery, 0);
} else {
$textl = 'Форум | Главная';
}
require_once('incfiles/head.php');
notify();
echo '<div class="phdr">';
if (isset($_GET['view_cat'])) {
echo '<a href="/forum.php">Форум</a> | ';
}
$homeTopicCount = mysql_num_rows($query);
if ($homeTopicCount === 0) {
echo 'Категорий пока нет!';
}
while ($homeCatArr = mysql_fetch_array($query)) {
$c++;
echo '<b><a style="moz-border-radius: 6px #ffffff;" href="?view_cat='. $homeCatArr['id'].'">'. out($homeCatArr['title']) .'</a></b>';
}
echo '</div>';
if ($user_id) {
echo '<div class="gmenu"><a href="?add_topic'. (isset($_GET['view_cat']) ? '&kat_id='.$_GET['view_cat'] : '') .'">Создать тему</a></div>';
if ($rights >= 7) {
echo '<div class="gmenu"><a href="?cat_admin">Управление категориями</a></div>';
}
}
if (isset($_GET['view_cat'])) {
$homeQueryThemes = mysql_query('SELECT * FROM `mini_forum`
WHERE `type` = "theme" AND `cid` = "'. (int)$_GET['view_cat'] .'" ORDER BY `last_time` DESC LIMIT '.(int)$_GET['start'] .', '. ((int)$_GET['start'] + 10) .' ');
$homeCount = mysql_num_rows(mysql_query('SELECT * FROM `mini_forum`
WHERE `type` = "theme" AND `cid` = "'. (int)$_GET['view_cat'] .'" '));
} else {
$homeQueryThemes = mysql_query('SELECT * FROM `mini_forum`
WHERE `type` = "theme" ORDER BY `last_time` DESC LIMIT '.(int)$_GET['start'] .', '. ((int)$_GET['start'] + 10) .' ');
$homeCount = mysql_num_rows(mysql_query('SELECT * FROM `mini_forum` WHERE `type` = "theme"'));
}
if ($homeCount === 0) {
echo '<div class="rmenu">Тем не найдено!</div>';
} else {
while ($homeTopicArr = mysql_fetch_array($homeQueryThemes)) {
if ($div === 'bmenu') {
$div = 'menu';
} elseif ($div === 'menu') {
$div = 'bmenu';
} else {
$div = 'menu';
}
echo '<div class="'. $div .'"><table cellpadding="2" cellspacing="0"><tr><td>' ;
if (file_exists('files/photo/' . $homeTopicArr['last_user_id'] .'_small.png')) {
echo '<img src="../files/photo/' . $homeTopicArr['last_user_id'] .'_small.png" width="50" height="50" alt="ava" /> ';
} elseif (file_exists('files/photo/' . $homeTopicArr['last_user_id'] .'_small.jpg')) {
echo '<img src="../files/photo/' . $homeTopicArr['last_user_id'] .'_small.jpg" width="50" height="50" alt="ava" /> ';
} elseif (file_exists('files/photo/' . $homeTopicArr['last_user_id'] .'_small.jpeg')) {
echo '<img src="../files/photo/' . $homeTopicArr['last_user_id'] .'_small.jpeg" width="50" height="50" alt="ava" /> ';
} elseif (file_exists('files/photo/' . $homeTopicArr['last_user_id'] .'_small.gif')) {
echo '<img src="../files/photo/' . $homeTopicArr['last_user_id'] .'_small.gif" width="50" height="50" alt="ava" /> ';
} else {
echo '<img src="../images/empty.png" width="50" height="50" alt="ava" /> ';
}
echo '</td> <td> <b><a href="?view_topic='.$homeTopicArr['id'] .'">'. out($homeTopicArr['title']) .'</a></b>
<br/> '.mysql_num_rows(mysql_query('SELECT `id` FROM `mini_forum` WHERE `type` = "msg" AND `tid` = "'. $homeTopicArr['id'] .'"')) .'
сообщений. Последнее от <a href="/str/anketa.php?id='.$homeTopicArr['last_user_id'] .'">
<b>'.mysql_result(mysql_query('SELECT `imname` FROM `users` WHERE `id` = "'. $homeTopicArr['last_user_id'] .'" '), 0) .'
'.mysql_result(mysql_query('SELECT `name` FROM `users` WHERE `id` = "'. $homeTopicArr['last_user_id'] .'" '), 0) .'</b></a>
('. date("d.m.Y / H:i", $homeTopicArr['last_time']) .')
</td></tr></table>
</div>';
}
}
if ($homeCount > 10) {
echo '<p>'. pagenav('?view_topic='. (int)$_GET['view_topic'] .'&', (int)$_GET['start'], $homeCount, 10) .'</p>';
}
if ($user_id) {
echo '<div class="gmenu"><a href="?add_topic'. (isset($_GET['view_cat']) ? '&kat_id='.$_GET['view_cat'] : '') .'">Создать тему</a></div>';
if ($rights >= 7) {
echo '<div class="gmenu"><a href="?cat_admin">Управление категориями</a></div>';
}
echo '<div class="phdr"><a href="?who">Кто в форуме : '. mysql_num_rows(mysql_query('SELECT `id` FROM `users` WHERE `place` = "'. $headmod .'" ')) .'</a></div>';
}
require_once('incfiles/end.php');