<?php
require_once('../../Connections/odonto_connection1.php');

$id_pre = $_GET['id_pre'];
$negocio = $_GET['negocio'];
$orden = $_GET['orden'];
$id_categ = $_GET['id_categ'];
$orden_original = unserialize($_GET['orden_original']);

$valor_inicial = $orden_original[$id_pre];
//echo $valor_inicial;
//print_r($orden_original);
//echo "<br>";
if($orden > $valor_inicial){
	for($i=$orden;$i > $valor_inicial;$i--){
		foreach($orden_original as $key => $value){
			if($value == $i){
				$x = $i - 1;
				$q = "UPDATE precios SET orden = $x WHERE id_pre = $key LIMIT 1";
				$rs = mysqli_query($odonto_connection,$q) or die(mysqli_error());
			}
		}
	}
}
else{
	for($i=$orden;$i < $valor_inicial;$i++){
		foreach($orden_original as $key => $value){
			if($value == $i){
				$x = $i + 1;
				$q = "UPDATE precios SET orden = $x WHERE id_pre = $key LIMIT 1";
				$rs = mysqli_query($odonto_connection,$q) or die(mysqli_error());
			}
		}
	}
}
$regreso = "negocio_3.php?id_categ=".$id_categ;
header("Location:".$regreso);

?>