<?php
//
$SYS_FOC="Tip";
//
$Tip=VU($_POST['Tip']);
$Nom=VU($_POST['Nom']);
//
$LIMPIAR=0;
//--------------------------------------------------------------------------
PID($StrId,V($_GET['Id']),$StrCmd,$LStrPag,V($_GET['Pag']));
//--------------------------------------------------------------------------
if(strlen($StrId)>0 && $StrCmd=="AR"){
	$Id=$StrId;
	$r=gr("ges_puertos","id_pto=$Id");
	$Tip=$r['pto_tip'];
	$Nom=$r['pto_nom'];
}
//
if($StrCmd=="L"){
	$LIMPIAR=1;
}	
//
if($StrCmd=="G" || $StrCmd=="M"){
//
}
//
if($StrCmd=="G"){	
	if(gn("count(*)","ges_puertos","pto_nom='$Nom'")>0){
		$SYS_MSG="Nombre ya registrado";
		$OK=0;
	}
	if($OK==1){
		$Id=GenId("id_pto","ges_puertos");
		$s="INSERT INTO ges_puertos VALUES ($Id,'$Tip','$Nom')";
		ejt($s);		
		//BIT
		$_BIT_MOD_ID=$Id;
		$_BIT_SQL_CAB=$s;
		$_BIT_SQL_DET="";
		$_BIT_PHP="ges_puertos.php";
		$_BIT_ID=BIT_ADD("MANTENIMIENTO","PUERTOS","GUARDAR",$_BIT_MOD_ID,$_BIT_SQL_CAB,$_BIT_SQL_DET,$_BIT_PHP);
		BIT_DET_ADD($_BIT_ID,$s);
		//BIT				
		$SYS_MSG="Datos registrados";
		$LIMPIAR=1;
	}
}
//
if($StrCmd=="M"){
	if(gn("count(*)","ges_puertos","pto_nom='$Nom' AND id_pto<>$StrId")>0){
		$SYS_MSG="Nombre ya registrado";
		$OK=0;
	}
	if($OK==1){
		$s="UPDATE ges_puertos 
			SET pto_tip='$Tip',
				pto_nom='$Nom' 
			WHERE id_pto=$StrId";
		ejt($s);		
		//BIT
		$_BIT_MOD_ID=$StrId;
		$_BIT_SQL_CAB=$s;
		$_BIT_SQL_DET="";
		$_BIT_PHP="ges_puertos.php";
		$_BIT_ID=BIT_ADD("MANTENIMIENTO","PUERTOS","MODIFICAR",$_BIT_MOD_ID,$_BIT_SQL_CAB,$_BIT_SQL_DET,$_BIT_PHP);
		BIT_DET_ADD($_BIT_ID,$s);
		//BIT				
		$SYS_MSG="Datos actualizados";
		$LIMPIAR=1;
	}
}
//
if($StrCmd=="E"){
	if(gn("count(*)","ges_invoice","in_id_p_ori=$StrId")>0){
		$SYS_MSG="El puerto esta relacionado a uno o mas invoice";
		$OK=0;
	}
	if($OK==1){
		if(gn("count(*)","ges_invoice","in_id_p_des=$StrId")>0){
			$SYS_MSG="El puerto esta relacionado a uno o mas invoice";
			$OK=0;
		}
	}
	if($OK==1){	
		$s="DELETE FROM ges_puertos WHERE id_pto=$StrId";
		ejt($s);
		//BIT
		$_BIT_MOD_ID=$StrId;
		$_BIT_SQL_CAB=$s;
		$_BIT_SQL_DET="";
		$_BIT_PHP="ges_puertos.php";
		$_BIT_ID=BIT_ADD("MANTENIMIENTO","PUERTOS","ELIMINAR",$_BIT_MOD_ID,$_BIT_SQL_CAB,$_BIT_SQL_DET,$_BIT_PHP);
		BIT_DET_ADD($_BIT_ID,$s);
		//BIT	
		$SYS_MSG="Datos eliminados";
		$LIMPIAR=1;	
	}
}
//
if($LIMPIAR==1){
	$StrId="";
	$Tip="";
	$Nom="";
}
?>
