<?
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("../../conexion/conectar.php");

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

mysqli_query($conexion->CONEXION,"delete from proveedores where rfc_receptor='".$_SESSION['RFC_RECEPTOR_PORTAL']."'");

$ban=false;

for($i=0; $i < count($_POST['checkRFC']); $i++){
	if(mysqli_query($conexion->CONEXION,"insert into proveedores set rfc='".$_POST['checkRFC'][$i]."', rfc_receptor='".$_SESSION['RFC_RECEPTOR_PORTAL']."'")){
		$ban=true;
	}
}

$result = mysqli_query($conexion->CONEXION,"select * from proveedores where rfc='".$_SESSION['RFC_RECEPTOR_PORTAL']."' and rfc_receptor='".$_SESSION['RFC_RECEPTOR_PORTAL']."' LIMIT 1");
if(mysqli_num_rows($result) <= 0){
	mysqli_query($conexion->CONEXION,"insert into proveedores set rfc='".$_SESSION['RFC_RECEPTOR_PORTAL']."', rfc_receptor='".$_SESSION['RFC_RECEPTOR_PORTAL']."'");
}

if($ban){
?><script>alert("Se han guardado las referencias correctamente");</script><?
}

?>