<?
session_name('portal_absa');
session_start();
if(!isset($_SESSION['usuario_p_prov_absa']) || trim($_SESSION['usuario_p_prov_absa']) == "" || trim(strtoupper($_SESSION["URL_PORTAL"]."admin.php")) != trim(strtoupper($_SERVER['HTTP_REFERER']))){
	?><script>window.location.href="<?=$_SESSION["URL_PORTAL"]."index.php"?>"</script><?
	exit;
}
require_once "../../conexion/conectar.php";
require_once "../../libs/funciones.php";

$conexion = new CONDB();
$conexion->conectar();

if(!isset($_REQUEST['rfc'])){
	?><script>$j_6.messager.alert("Error","Faltan parametros","error");</script><?exit;
}

$set="";
if($_REQUEST["tipo"] == "int"){
	$set = $_REQUEST["campo"]."=".$_REQUEST["valor"];
}else if($_REQUEST["tipo"] == "check"){
	if(strtolower(trim($_REQUEST["valor"])) == "true"){
		$_REQUEST["valor"] = "1";
	}else{
		$_REQUEST["valor"] = "0";
	}
	$set = $_REQUEST["campo"]."='".$_REQUEST["valor"]."'";
}else{
	$set = $_REQUEST["campo"]."='".$_REQUEST["valor"]."'";
}

$q = "INSERT INTO proveedores SET $set,rfc='".$_REQUEST['rfc']."',rfc_receptor='".$_SESSION['RFC_RECEPTOR_PORTAL']."' ON DUPLICATE KEY UPDATE $set";


if(!$result = mysqli_query($conexion->CONEXION,$q)){
	?><script>$j_6.messager.alert("Error","Ocurrio un error al actualizar la configuraci&oacute;n. <?=mysqli_error($conexion->CONEXION)?>","error");</script><?exit;
}

if(mysqli_affected_rows($conexion->CONEXION) > 0){
	?><!--<script>$j_6.messager.alert("Informaci&oacute;n","Se ha actualizado correctamente la configuraci&oacute;n.","info");</script>--><?exit;
}else{
	?><script>$j_6.messager.alert("Advertencia","No se actualizo el registro.","warning");</script><?exit;
}

?>