<?php
  ///////////////////////////////////////////////////
  //перемещение строк вверх/вниз
  //2009 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////
  require_once "../utils/chlang.php";

  $title=$titlepage = $TEXT['menu-btn37-title'];
  require_once "../config_a.php";
  require_once "../utils/functions.php";
  require_once "../utils/top_adm_film.php";

  if($result2['administrator'] == 0) {puterror($result2['skin'],$TEXT['error-loginform2']); require_once "../utils/bottom_adm_film.php"; exit();}
  if(empty($_GET['bl_id'])) {puterror($result2['skin'],$TEXT['error-booklang5']); require_once "../utils/bottom_adm_film.php"; exit();}
  if(strlen($_GET['bl_id'])>5) {puterror($result2['skin'],$TEXT['error-booklang6']); require_once "../utils/bottom_adm_film.php"; exit();}
  if(empty($_GET['position'])) {puterror($result2['skin'],$TEXT['error-booklang11']); require_once "../utils/bottom_adm_film.php"; exit();}
  if(strlen($_GET['position'])>5) {puterror($result2['skin'],$TEXT['error-booklang2']); require_once "../utils/bottom_adm_film.php"; exit();}
  if(empty($_GET['moving'])) {puterror($result2['skin'],$TEXT['error-booklang12']); require_once "../utils/bottom_adm_film.php"; exit();}
  if(strlen($_GET['moving'])>5) {puterror($result2['skin'],$TEXT['error-booklang13']); require_once "../utils/bottom_adm_film.php"; exit();}

  $_GET['position'] = rep($_GET['position']);
  $_GET['bl_id'] = rep($_GET['bl_id']);
  $_GET['moving'] = rep($_GET['moving']);

  if($_GET['moving']=="up"){
  $query_move = "SELECT bl_id, position FROM `tbl_booklang` WHERE `position`<'".$_GET['position']."' ORDER BY `position` DESC LIMIT 1 ";
  $result_move = mysqli_query($dbcnx,$query_move);
  if(!$result_move) {puterror($result2['skin'],$TEXT['error-tbl23']); require_once "../utils/bottom_adm_film.php"; exit();}
   $result2_move = mysqli_fetch_array($result_move);
   if($result2_move['position'] == 0) {puterror($result2['skin'],$TEXT['error-booklang14']); require_once "../utils/bottom_adm_film.php"; exit();}

   $query = "UPDATE `tbl_booklang` SET `position`='".$result2_move['position']."' WHERE `bl_id`='".$_GET['bl_id']."' ";
   if(mysqli_query($dbcnx,$query))
   {
   $query = "UPDATE `tbl_booklang` SET `position`='".$_GET['position']."' WHERE `bl_id`='".$result2_move['bl_id']."' ";
     if(mysqli_query($dbcnx,$query))
      {
       echo "<html><head>
          <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php' />
          </head></html>";
       } else {puterror($result2['skin'],$TEXT['error-booklang14']); require_once "../utils/bottom_adm_film.php"; exit();}
   } else {puterror($result2['skin'],$TEXT['error-booklang14']); require_once "../utils/bottom_adm_film.php"; exit();}
  }
  else
  {
  $query_move = "SELECT bl_id, position FROM `tbl_booklang` WHERE `position`>'".$_GET['position']."' ORDER BY `position` LIMIT 1";
  $result_move = mysqli_query($dbcnx,$query_move);
  if(!$result_move) {puterror($result2['skin'],$TEXT['error-tbl23']); require_once "../utils/bottom_adm_film.php"; exit();}
   $result2_move = mysqli_fetch_array($result_move);
  if($result2_move['position'] == 0) {puterror($result2['skin'],$TEXT['error-booklang14']); require_once "../utils/bottom_adm_film.php"; exit();}

  $query = "UPDATE `tbl_booklang` SET `position`='".$_GET['position']."' WHERE `bl_id`='".$result2_move['bl_id']."' ";
  if(mysqli_query($dbcnx,$query))
  {
   $query = "UPDATE `tbl_booklang` SET `position`='".$result2_move['position']."' WHERE `bl_id`='".$_GET['bl_id']."' ";
     if(mysqli_query($dbcnx,$query))
      {
       echo "<html><head>
          <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php' />
          </head></html>";
        } else {puterror($result2['skin'],$TEXT['error-booklang14']); require_once "../utils/bottom_adm_film.php"; exit();}
    } else {puterror($result2['skin'],$TEXT['error-booklang14']); require_once "../utils/bottom_adm_film.php"; exit();}
  }
  require_once "../util/bottom.php";
?>