<html>
<head>
<title>CREAR NUEVO JEFATURA</title>
<script type="text/javascript"> 
function VentanaClose(){ 
   
}
function CrearNuevaJefatura(){
var nom = document.getElementById("nomj").value;
var abrev = document.getElementById("abrevj").value;
document.location="nuevojefaturadpto.php?nom="+nom+"&abrev="+abrev;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="../styles/Style.css">
</head>
<body>
<?php
include("../bd/sql_variables.php");
$db_conexion= mysql_connect("$sql_host", "$sql_usuario", "$sql_pass") or die(header ("No Disponible Servidor de Base de Datos"));
mysql_select_db("$sql_db");

$error=3;

if(isset($_GET['nom']) && isset($_GET['abrev'])){
$nom=$_GET['nom'];
$abrev=$_GET['abrev'];
$error=0;

$sqlnjef="select j_id from tb_jefatura order by j_id desc limit 1";
$resultnf = mysql_query($sqlnjef);
	if(mysql_num_rows($resultnf)!=0){
		while ($rownf= mysql_fetch_array($resultnf)){
		 $nf = $rownf['j_id'] + 1;
		}
	}else{
		$nf=1;
	}
	
	if($nf>0){	
	$sql="insert into tb_jefatura values ('$nf',upper('$abrev'),upper('$nom'))";
	$result = mysql_query($sql);
	}else{
	$error=1;
	}
}

$cadena = $cadena."<br><table align='center' class='TableDiseno'>";
$cadena = $cadena."<tr><td align='center' colspan='2' width='450' height='40' class='LlenarTablaGareaTitulo'><b>CREAR NUEVA JEFATURA</b></td></tr>";
$cadena = $cadena."<tr><td class ='FacetDataTextC' colspan='2' align='center'><font color='red'><b>";
if($error==1){
$cadena = $cadena." No se registro correctamente";
}elseif($error==0){
echo "<script type='text/javascript'>window.opener.location.reload(); window.close();</script>";
}
$cadena = $cadena."</b></font></td></tr>";
$cadena = $cadena."<tr><td class ='FacetDataTextC' align='left' width='120' >Nombre Jefatura</td><td class ='FacetDataTextC'><input type='text' name='nomj' id='nomj' value='$nom' size='50'></td></tr>";
$cadena = $cadena."<tr><td class ='FacetDataTextC' align='left' >Abreviatura</td><td class ='FacetDataTextC'><input type='text' name='abrevj' id='abrevj' value='$abrev' size='15'></td></tr>";
$cadena = $cadena."<tr><td align='center' colspan='2'><input type='button' value='Crear' onClick='CrearNuevaJefatura()'><input type='button' value='Cerrar'></td></tr>";
$cadena = $cadena."</table>";
echo $cadena;
?>
</body>
</html>
