<?php
# Script by seg0ro http://mobilarts.ru
# Not for sale!!!

defined('_IN_JOHNCMS') or die('Error: restricted access');

$textl .= ' | Перемещение';
require_once('../incfiles/head.php');

if (!$forum){
  echo functions::display_error('Отсутствует идентификатор форума!<br /><a href="index.php">Форум</a>');
  require_once('../incfiles/end.php');
  exit;
}

if ($rights < 9){
  echo functions::display_error('У вас недостаточно прав для просмотра этой страницы!<br /><a href="index.php">Форум</a>');
  require_once('../incfiles/end.php');
  exit;
}

$go = $forumRes['parent'] ? 'forum='.$forumRes['parent'] : '';
$sql = $forumRes['parent'] ? " = '".$forumRes['parent']."'" : " = 0"; 

if (isset($_GET['up']) && !isset($_GET['down'])){
  $forumUp = mysql_fetch_array(mysql_query("SELECT `forum`, `sort`, `forumname` FROM `forum_forums` WHERE `parent`$sql AND `sort` < '".$forumRes['sort']."' ORDER BY `sort` DESC LIMIT 1 "));
  if ($forumUp['sort'] && $forumUp != $forum){
    mysql_query("UPDATE `forum_forums` SET `sort` = '".$forumUp['sort']."' WHERE `forum` = '$forum' LIMIT 1 ");
    mysql_query("UPDATE `forum_forums` SET `sort` = '".$forumRes['sort']."' WHERE `forum` = '".$forumUp['forum']."' LIMIT 1 ");
  }
}elseif (isset($_GET['down']) && !isset($_GET['up'])){
  $forumDown = mysql_fetch_array(mysql_query("SELECT `forum`, `sort`, `forumname` FROM `forum_forums` WHERE `parent`$sql AND `sort` > '".$forumRes['sort']."' ORDER BY `sort` ASC LIMIT 1 "));
  if ($forumDown['sort'] && $forumDown != $forum){
    mysql_query("UPDATE `forum_forums` SET `sort` = '".$forumDown['sort']."' WHERE `forum` = '$forum' LIMIT 1 ");
    mysql_query("UPDATE `forum_forums` SET `sort` = '".$forumRes['sort']."' WHERE `forum` = '".$forumDown['forum']."' LIMIT 1 ");
  }
}else{
  echo functions::display_error('Неверные данные!<br /><a href="index.php">Форум</a>');
  require_once('../incfiles/end.php');
  exit;
}
header ('Location: index.php?'.$go);