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

  $title=$TEXT['menu-btn35-title'];
  require_once "config_a.php";
  require_once "utils/functions.php";
  require_once "utils/top_film.php";

  if($result2['administrator'] == 0) {puterror2($result2['skin'],$TEXT['error-loginform2']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_GET['film_id'])>255) {puterror2($result2['skin'],$TEXT['error-film6']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_GET['cicle_id'])>5) {puterror2($result2['skin'],$TEXT['error-cicle6']); require_once "utils/bottom_film.php"; exit();}
  if(empty($_GET['position'])) {puterror2($result2['skin'],$TEXT['error-booklang11']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_GET['position'])>5) {puterror2($result2['skin'],$TEXT['error-booklang10']); require_once "utils/bottom_film.php"; exit();}
  if(empty($_GET['moving'])) {puterror2($result2['skin'],$TEXT['error-booklang12']); require_once "utils/bottom_film.php"; exit();}
  if(strlen($_GET['moving'])>5) {puterror2($result2['skin'],$TEXT['error-booklang13']); require_once "utils/bottom_film.php"; exit();}

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

  if($_GET['moving']=="up"){
  $query_move = "SELECT film_id, film_num FROM `tbl_film` WHERE `film_num`<'".$_GET['position']."' AND `cicle_id`='".$_GET['cicle_id']."' ORDER BY `film_num` DESC LIMIT 1 ";
  $result_move = mysqli_query($dbcnx,$query_move);
  if(!$result_move) {puterror2($result2['skin'],$TEXT['error-tbl3']); require_once "utils/bottom_film.php"; exit();}
   $result2_move = mysqli_fetch_array($result_move);
   if($result2_move['film_num'] == 0) {puterror2($result2['skin'],$TEXT['error-booklang14']); require_once "utils/bottom_film.php"; exit();}

   $query = "UPDATE `tbl_film` SET `film_num`='".$result2_move['film_num']."' WHERE `film_id`='".$_GET['film_id']."' ";
   if(mysqli_query($dbcnx,$query))
   {
   $query = "UPDATE `tbl_film` SET `film_num`='".$_GET['position']."' WHERE `film_id`='".$result2_move['film_id']."' ";
     if(mysqli_query($dbcnx,$query))
      {
       echo "<html><head>
          <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=film-extsearch.php?cicle_id=".$_GET['cicle_id']."&cicle_ch=on' />
          </head></html>";
       } else {puterror2($result2['skin'],$TEXT['error-booklang14']); require_once "utils/bottom_film.php"; exit();}
   } else {puterror2($result2['skin'],$TEXT['error-booklang14']); require_once "utils/bottom_film.php"; exit();}
  }
  else
  {
  $query_move = "SELECT film_id, film_num FROM `tbl_film` WHERE `film_num`>'".$_GET['position']."' AND `cicle_id`='".$_GET['cicle_id']."' ORDER BY `film_num` LIMIT 1";
  $result_move = mysqli_query($dbcnx,$query_move);
  if(!$result_move) {puterror2($result2['skin'],$TEXT['error-tbl3']); require_once "utils/bottom_film.php"; exit();}
   $result2_move = mysqli_fetch_array($result_move);
  if($result2_move['film_num'] == 0) {puterror2($result2['skin'],$TEXT['error-filmlang14']); require_once "utils/bottom_film.php"; exit();}

  $query = "UPDATE `tbl_film` SET `film_num`='".$_GET['position']."' WHERE `film_id`='".$result2_move['film_id']."' ";
  if(mysqli_query($dbcnx,$query))
  {
   $query = "UPDATE `tbl_film` SET `film_num`='".$result2_move['film_num']."' WHERE `film_id`='".$_GET['film_id']."' ";
     if(mysqli_query($dbcnx,$query))
      {
       echo "<html><head>
          <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=film-extsearch.php?cicle_id=".$_GET['cicle_id']."&cicle_ch=on' />
          </head></html>";
        } else {puterror2($result2['skin'],$TEXT['error-booklang14']); require_once "utils/bottom_film.php"; exit();}
    } else {puterror2($result2['skin'],$TEXT['error-booklang14']); require_once "utils/bottom_film.php"; exit();}
  }
  require_once "utils/bottom_film.php";
?>