Файл: modules/forum/index.php
Строк: 230
<?php
/****
* @package LiveCMS
* @link livecms.org
* @author MyZik
* @version See attached file VERSION.txt
* @license See attached file LICENSE.txt
* @copyright Copyright (C) LiveCMS Development Team
****/
$lang_forum = load_lng('forum'); // Подключаем файл языка
  $title = $lang_forum['forum']; // Заголовок страницы
  $module = 'forum'; // Модуль
  $icons_dir = '/design/icons/forum/'; // папка и иконками
  /**
    * Поднятие уровня категории
  **/
  if (isset($_GET['up']) && is_numeric($_GET['up']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_categories` WHERE `id` = '" . num($_GET['up']) . "'"), 0) != 0 && $user['rights'] >= 8) {
    $res = mysql_fetch_assoc(mysql_query("SELECT * FROM `cms_forum_categories` WHERE `id` = '" .num($_GET['up']) . "'"));
    $position = $res['position'] - 1;
    mysql_query("UPDATE `cms_forum_categories` SET `position` = `position` + 1 WHERE `position` = '$position'");
    mysql_query("UPDATE `cms_forum_categories` SET `position` = '$position' WHERE `id` = '" . num($_GET['up']) . "'");
    header('Location: index.php');
        }
  /**
    * Понижение уровня категории
  **/
  if (isset($_GET['down']) && is_numeric($_GET['down']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_categories` WHERE `id` = '" . num($_GET['down']) . "'"), 0) != 0 && $user['rights'] >= 8) {
    $res = mysql_fetch_assoc(mysql_query("SELECT * FROM `cms_forum_categories` WHERE `id` = '" .num($_GET['down']) . "'"));
    $position = $res['position'] + 1;
    mysql_query("UPDATE `cms_forum_categories` SET `position` = `position` - 1 WHERE `position` = '$position'");
    mysql_query("UPDATE `cms_forum_categories` SET `position` = '$position' WHERE `id` = '" . num($_GET['down']) . "'");
    header('Location: index.php');
        }
  /**
    * Добавление категории
  **/
  if (isset($_GET['add'])) {
    /**
      Проверяем права доступа
    **/
    if ($user['rights'] < 8) {
    require_once(HOME .'/incfiles/header.php');
    echo '<div class="error">' . $lang['error_rights'] . '</div>';
    echo '<div class="home">' .
    '<img src="/design/themes/' . $set_user['theme'] . '/images/back.png" alt="" /> <a href="index.php">' . $lang['back'] . '</a>' .
    '</div>';
    require_once(HOME .'/incfiles/footer.php');
      }
    require_once(HOME .'/incfiles/header.php'); // подключаем шапку
    /**
      * Небольшая панель навигации
    **/
    echo '<div class="title"><a href="/forum/">' . $lang['forum'] . '</a></div>';
    if (isset($_POST['add'])) {
      $name = input(mb_substr($_POST['name'], 0, 60));
      $text = input(mb_substr($_POST['text'], 0, 300));
      /**
        * Проверяем длину названия категории
      **/
      if (strlen($name) < 2)
        $err[] = $lang_forum['short_name_category'];
      /**
        * Проверяем, существует ли категория в БД
      **/
      if (mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_categories` WHERE `name` = '$name' AND `text` = '$text'"), 0) != 0)
        $err[] = $lang_forum['category_exists'];
      /**
        * Если не было ошибок, заносим данные
      **/
      if (!isset($err)) {
        $position = mysql_fetch_assoc(mysql_query("SELECT `position` FROM `cms_forum_categories` ORDER BY `position` DESC LIMIT 1"));
        mysql_query("INSERT INTO `cms_forum_categories` (`position`, `name`, `text`) VALUES ('" . ($position['position'] + 1) . "', '$name', '$text')");
        echo display_message($lang_forum['add_category_success']);
        /**
          * Нижняя панель навигации
        **/
        echo '<div class="home"><img src="/design/themes/' . $set_user['theme'] . '/images/back.png" alt="<" /> <a href="index.php?add">' . $lang['back'] . '</a><br />' . 
        '<img src="/design/themes/' . $set_user['theme'] . '/images/back.png" alt="<" /> <a href="index.php">' . $lang_forum['forum'] . '</a>' .
        '</div>';
        require_once(HOME .'/incfiles/footer.php'); // подключаем ноги
          } else {
        echo error($err); // показываем ошибки, если они имеются
          }
            }
    /**
      * Форма
    **/
    echo '<div class="main"><form method="post" action="index.php?add">' .
    $lang_forum['category_name'] . '<br />' .
    '<input type="text" name="name" value="" /><br />' .
    $lang_forum['category_text'] . '<br />' .
    '<textarea name="text"></textarea><br />' .
    $lang_forum['category_text_info'] . '<br />' .
    '<input type="submit" name="add" value="' . $lang['add'] . '" />' .
    '</form></div>';
    require_once(HOME .'/incfiles/footer.php'); // подключаем ноги
    }
  /**
    * Редактирование категории
  **/
  elseif (isset($_GET['edit'])) {
    /**
      * Проверяем права доступа
    **/
  if ($user['rights'] < 8) {
    require_once(HOME .'/incfiles/header.php');
    echo '<div class="error">' . $lang['error_rights'] . '</div>';
    require_once(HOME .'/incfiles/footer.php');
      }
    require_once(HOME .'/incfiles/header.php'); // подключаем шапку
    /**
      * Проверяем введенный параметр
    **/
    if (empty($_GET['edit']) || !is_numeric($_GET['edit']))
      $err[] = $lang['error_parameter'];
    /**
      * Проверяем наличие категории
    **/
    if (mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_categories` WHERE `id` = '" . num($_GET['edit']) . "'"), 0) == 0)
      $err[] = $lang_forum['category_not_exists'];
    $ID = num($_GET['edit']);
    $category = mysql_fetch_assoc(mysql_query("SELECT * FROM `cms_forum_categories` WHERE `id` = '$ID'"));
    /**
      * Небольшая панель навигации
    **/
    echo '<div class="title"><a href="/forum/">' . $lang['forum'] . '</a> | <b> ' . txt($category['name']) . '</b></div>';
    if (isset($_POST['save'])) {
      $name = input(mb_substr($_POST['name'], 0, 60));
      $text = input(mb_substr($_POST['text'], 0, 300));
      /**
        * Проверяем длину названия категории
      **/
      if (strlen($name) < 2)
        $err[] = $lang_forum['short_name_category'];
    /**
      * Проверяем, существует ли категория в БД
    **/
      if (mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_categories` WHERE `name` = '$name' AND `text` = '$text'"), 0) != 0)
        $err[] = $lang_forum['category_exists'];
      /**
        * Если не было ошибок, заносим данные
      **/
      if (!isset($err)) {
        mysql_query("UPDATE `cms_forum_categories` SET `name` = '$name', `text` = '$text' WHERE `id` = '$ID' LIMIT 1");
        echo display_message($lang_forum['edit_category_success']);
        /**
          * Нижняя панель навигации
        **/
        echo '<div class="home"><img src="/design/themes/' . $set_user['theme'] . '/images/back.png" alt="<" /> <a href="index.php?edit=' . $ID . '">' . $lang['back'] . '</a><br />' .
        '<img src="/design/themes/' . $set_user['theme'] . '/images/back.png" alt="<" /> <a href="index.php">' . $lang_forum['forum'] . '</a>' .
        '</div>';
        require_once(HOME .'/incfiles/footer.php'); // подключаем ноги
          } else {
        echo error($err); // показываем ошибки, если они имеются
        require_once(HOME .'/incfiles/footer.php'); // подключаем ноги
          }
            }
    /**
      * Форма
    **/
    echo '<div class="main"><form method="post" action="index.php?edit=' . $ID . '">' .
    $lang_forum['category_name'] . '<br />' .
    '<input type="text" name="name" value="' . $category['name'] . '" /><br />' .
    $lang_forum['category_text'] . '<br />' .
    '<textarea name="text">' . $category['text'] . '</textarea><br />' .
    $lang_forum['category_text_info'] . '<br />' .
    '<input type="submit" name="save" value="' . $lang['add'] . '" />' .
    '</form></div>';
    require_once(HOME .'/incfiles/footer.php'); // подключаем ноги
      }
  /**
    * Удаление категории
  **/
  elseif (isset($_GET['delete'])) {
    /**
      * Проверяем права доступа
    **/
  if ($user['rights'] < 8) {
    require_once(HOME .'/incfiles/header.php');
    echo '<div class="error">' . $lang['error_rights'] . '</div>';
    require_once(HOME .'/incfiles/footer.php');
      }
    require_once(HOME .'/incfiles/header.php'); // подключаем шапку
    /**
      * Проверяем введенный параметр
    **/
    if (empty($_GET['delete']) || !is_numeric($_GET['delete']))
      $err[] = $lang['error_parameter'];
    /**
      * Проверяем наличие категории
    **/
    if (mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_categories` WHERE `id` = '" . num($_GET['delete']) . "'"), 0) == 0)
      $err[] = $lang_forum['category_not_exists'];
    $category = mysql_fetch_assoc(mysql_query("SELECT * FROM `cms_forum_categories` WHERE `id` = '$ID'"));
    /**
      * Небольшая панель навигации
    **/
    echo '<div class="title"><a href="/forum/">' . $lang['forum'] . '</a> | <b>' . txt($category['name']) . '</b></div>';
    $ID = num($_GET['delete']);
    if (isset($_GET['yes'])) {
      /**
        * Если не было ошибок, удаляем категорию
      **/
      if (!isset($err)) {
        mysql_query("DELETE FROM `cms_forum_categories` WHERE `id` = '$ID' LIMIT 1");
        mysql_query("DELETE FROM `cms_forum_sections` WHERE `category_id` = '$ID'");
        mysql_query("DELETE FROM `cms_forum_topics` WHERE `category_id` = '$ID'");
        header("Location: index.php");
        exit;
        } else {
        echo error($err);
        require_once(HOME .'/incfiles/footer.php'); // подключаем ноги
      }
    } else {
        echo '<div class="error">' . $lang_forum['delete_category_info'] . '<br />' .
        '<a href="index.php?delete=' . $ID . '&yes"><input type="button" name="" value="' . $lang['delete'] . '" /></a> | <a href="index.php">' . $lang['cancel'] . '</a></div>';
        require_once(HOME .'/incfiles/footer.php'); // подключаем ноги
  }
  }
  /**
    * Показываем список категорий
  **/
  else {
    require_once(HOME .'/incfiles/header.php'); // подключаем шапку
    /**
      * Админские функции
    **/
    if ($user['rights'] >= 8)
      echo '<div class="home"><img src="/design/themes/' . $set_user['theme'] . '/images/act.png" alt="" /> <a href="index.php?add">' . $lang_forum['category_add'] . '</a></div>';
    /**
      * Настраиваем пагинацию
    **/
    $total = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_categories`"), 0);
    $req = mysql_query("SELECT * FROM `cms_forum_categories` ORDER BY `position` ASC LIMIT $start, $countMess"); 
    /**
      * Если нет результатов, показываем уведомление
    **/
    if ($total < 1) {
      echo '<div class="error">' . $lang_forum['categories_not_found'] . '</div>';
        }
    while ($res = mysql_fetch_assoc($req)) {
      echo ($i % 2) ? '<div class="list1">' : '<div class="list2">';
      $count = mysql_result(mysql_query("SELECT COUNT(*) FROM `cms_forum_sections` WHERE `category_id` = '" . $res['id'] . "' LIMIT 1"), 0);
      echo '<img src="' . $icons_dir . 'category.png" alt="[c]" /> <a href="category.php?id=' . $res['id'] . '">' . txt($res['name']) . '</a> [' . $count . ']' .
      ($user['rights'] >= 8 ? ' [<a href="index.php?up=' . $res['id'] . '">' . $lang_forum['up'] . '</a> | <a href="index.php?down=' . $res['id'] . '">' . $lang_forum['down'] . '</a> | <a href="index.php?edit=' . $res['id'] . '">' . $lang_forum['edit'] . '</a> | <a href="index.php?delete=' . $res['id'] . '">' . $lang_forum['delete'] . '</a>]' : '') .
      (!empty($res['text']) ? '<br /><span class="gray">' . output(txt($res['text'])) . '</span>' : '') . '</div>';
      $i++;
         } 
    /**
      * Пагинация
    **/
    if ($total > $countMess) {
      echo '<div class="home">' . display_pagination('index.php?', $start, $total, $countMess) . '</div>';
      }
    require_once(HOME .'/incfiles/footer.php'); // Подключаем ноги
    }
?>