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

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

  if($result2['administrator'] == 0) {puterror($result2['skin'],$TEXT['error-loginform2']); require_once "../utils/bottom_adm.php"; exit();}
  if(empty($_GET['izd_id'])) {puterror($result2['skin'],$TEXT['error-tip-izd5']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['izd_id'])>5) {puterror($result2['skin'],$TEXT['error-tip-izd6']); require_once "../utils/bottom_adm.php"; exit();}
  if(empty($_GET['position'])) {puterror($result2['skin'],$TEXT['error-booklang11']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['position'])>5) {puterror($result2['skin'],$TEXT['error-booklang10']); require_once "../utils/bottom_adm.php"; exit();}
  if(empty($_GET['moving'])) {puterror($result2['skin'],$TEXT['error-booklang12']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['moving'])>5) {puterror($result2['skin'],$TEXT['error-booklang13']); require_once "../utils/bottom_adm.php"; exit();}

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

  if($_GET['moving']=="up"){
  $query_move = "SELECT tip_izd_id, position FROM `tbl_tip_izd` WHERE `position`<'".$_GET['position']."' AND use_prog='1' ORDER BY `position` DESC LIMIT 1 ";
  $result_move = mysqli_query($dbcnx,$query_move);
  if(!$result_move) {puterror($result2['skin'],$TEXT['error-tbl15']); require_once "../utils/bottom_adm.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.php"; exit();}

   $query = "UPDATE `tbl_tip_izd` SET `position`='".$result2_move['position']."' WHERE `tip_izd_id`='".$_GET['izd_id']."' ";
   if(mysqli_query($dbcnx,$query))
   {
   $query = "UPDATE `tbl_tip_izd` SET `position`='".$_GET['position']."' WHERE `tip_izd_id`='".$result2_move['tip_izd_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.php"; exit();}
   } else {puterror($result2['skin'],$TEXT['error-booklang14']); require_once "../utils/bottom_adm.php"; exit();}
  }
  else
  {
  $query_move = "SELECT tip_izd_id, position FROM `tbl_tip_izd` WHERE `position`>'".$_GET['position']."' AND use_prog='1' ORDER BY `position` LIMIT 1";
  $result_move = mysqli_query($dbcnx,$query_move);
  if(!$result_move) {puterror($result2['skin'],$TEXT['error-tbl15']); require_once "../utils/bottom_adm.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.php"; exit();}

  $query = "UPDATE `tbl_tip_izd` SET `position`='".$_GET['position']."' WHERE `tip_izd_id`='".$result2_move['tip_izd_id']."' ";
  if(mysqli_query($dbcnx,$query))
  {
   $query = "UPDATE `tbl_tip_izd` SET `position`='".$result2_move['position']."' WHERE `tip_izd_id`='".$_GET['izd_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.php"; exit();}
    } else {puterror($result2['skin'],$TEXT['error-booklang14']); require_once "../utils/bottom_adm.php"; exit();}
  }
  require_once "../utils/bottom_adm.php";
?>