<? 

require_once('../../../conf/connection.php');
$nombreuser =$_GET["nombreuser"];
//extraer sucursal
       $query_sucu="SELECT * FROM user_sistem WHERE nombre='$nombreuser'";
	   $res_sucu=mysql_query($query_sucu);
	   $sucu=mysql_result($res_sucu,0,"sucursal");
//nombre suscursal
	   $query_nom="SELECT * FROM sucu WHERE codsucu='$sucu'";
	   $res_nom=mysql_query($query_nom);
	   $nom_sucu=mysql_result($res_nom,0,"nombre");
$hoy=date("d-m-Y");
$ano=date("Y");

            
?>
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
  

    <meta charset="utf-8">
    <title>INVENTARIO</title>
    <meta name="viewport" content="initial-scale = 1.0, maximum-scale = 1.0, user-scalable = no, width = device-width">

    <!--[if lt IE 9]><script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
    <link rel="stylesheet" href="../../../style.css" media="screen">
    <!--[if lte IE 7]><link rel="stylesheet" href="../style.ie7.css" media="screen" /><![endif]-->
    <link rel="stylesheet" href="../../../style.responsive.css" media="all">

    <script src="../../../jquery.js"></script>
    <script src="../../../script.js"></script>
    <script src="../../../script.responsive.js"></script>



<style>.art-content .art-postcontent-0 .layout-item-0 { border-top-width:1px;border-top-style:solid;border-top-color:#B1C9C7;margin-top: 10px;margin-bottom: 10px;  }
.art-content .art-postcontent-0 .layout-item-1 { border-right-style:solid;border-right-width:1px;border-right-color:#B1C9C7; padding-right: 10px;padding-left: 10px;  }
.ie7 .art-post .art-layout-cell {border:none !important; padding:0 !important; }
.ie6 .art-post .art-layout-cell {border:none !important; padding:0 !important; }

</style>
    <script>
$(document).ready(function(){
// Demo 5
$('#identidad').Rut({
  on_error: function(){ alert('Rut incorrecto'); },
  format_on: 'keyup' 
});
$("#content > ul").tabs();
});

function cerrar() {
			window.close();
		}
		
</script>  
 <script type="text/javascript" src="../js/jquery-1.6.2.js"></script>
   <script src="../js/jquery.Rut.js" type="text/javascript"></script>
  <script type="text/javascript" src="../../../funciones/scripts.js"></script>
  <script type="text/javascript">

 //He aqui la magia de AJAX gracias al Framework JQuery!
  $(document).ready(function(){
	  //programamos el vento click del boton enviar del formulario
	  $("#enviar").click(function() {
		  
		  //Variables del formulario
		  var cod=frm_add.codigo.value;
		  var fam=frm_add.familia.value;
		  var sucu=frm_add.sucu.value;
		   
		  //preguntamos si no hay campos vacios
		  if(cod!="" && fam!="" )
		  {
		      //Enviamos mediante el metodo post de JQuery $.post("archivo.php",{parametros}, callback);
		      $.post("add_reg.php", {enviar:frm_add.enviar.value, codigo:cod, familia:fam, sucu:sucu }, function(output){
			    //El parametro output, recibe como salida lo generado por el script php
				alert(output);
				//con esta linea limpiamos el formulario
				document.frm_add.reset();
				window.location.reload();
		      });
		  }
		  else
		  {
			  alert("Campos obligatorios (*) vacios!");
		  }
	  });
  });
</script>
 <script>
function borrar(codigo){
			miPopup = window.open("borrar_reg.php?codigo=" + codigo + "&nombreuser=<? echo $nombreuser ?>&sucu=<? echo $sucu ?>","miwin","width=700,height=650,scrollbars=yes");
			miPopup.focus();
		}
		
		

		</script>

</head>
<body>
<div id="art-main">

<div class="art-sheet clearfix">
            <div class="art-layout-wrapper">
                <div class="art-content-layout">
                  <div class="art-content-layout-row">
                    <div class="art-layout-cell art-content"><article class="art-post art-article">
                                
                                                
                                <div class="art-postcontent art-postcontent-0 clearfix"><div class="art-content-layout">
    <div class="art-content-layout-row">
    <div class="art-layout-cell layout-item-1" style="width: 100%" >
        <h3>Agregar familia | Sucursal: <? echo $nom_sucu ?></h3>
     <p >
       <form id="frm_add" name="frm_add" method="post">
       <input type="hidden" name="sucu" id="sucu" value="<? echo $sucu ?>"  />
       <fieldset><legend>Nuevo Registro</legend>
   <table width="514">
     
     <tr>
       <td width="168" height="32" align="right">CODIGO DE FAMILIA</td>
       <td width="334"><input type="text" name="codigo" id="codigo"  /></td>
     </tr>
     <tr>
       <td height="30" align="right">NOMBRE DE FAMILIA </td>
                 
       <td><input type="text" name="familia" id="familia"  /></td>
     </tr>
     
     <tr>
       <td colspan="2" align="right"><input type="button" id="enviar" name="enviar" value="Guardar" class="art-button" />
         <input type="reset" id="cancel" name="cancel" value="Cancelar" class="art-button" />
         <input type="submit" value="Cerrar ventana" class="art-button" onClick="cerrar()" /></td>
     </tr>
     </table>
     </fieldset>
</form>
 

     
     <hr> </p>
     <p><?  
		 $buscar="select * from familias where ucase(sucu) like \"%$sucu%\" order by codfamilia ";
		   $r=mysql_query($buscar,$conn) or die("Error en el query: ".mysql_error());
		   $n=mysql_num_rows($r);
		    //si hay registros los procesamos
			if($n>0)
			{
				?>
            <div>
              <table  width="518" border="0">
                <tr bgcolor="#69BFE0" >
                  <td width="164" bgcolor="#69BFE0">CODIGO</td>
                  <td width="287" bgcolor="#69BFE0">NOMBRE</td>
                  <td width="53" bgcolor="#69BFE0">&nbsp;</td>
                  </tr>
                <?
				while($row=mysql_fetch_assoc($r))
				{ 
					?>
                <tr>
                 
                  <td><? echo $row["codfamilia"]; ?></td>
                  <td><? echo $row["nombre"]; ?></td>
                  <td colspan="7"><a href="#"><img src="../../../images/delete.png"  alt="Eliminar" width="16" height="16" / onClick="borrar('<? echo  $row["codfamilia"] ?>')" /></a></td>
                  </tr>
                
                <? }?>
                <tr>
                  <td colspan="9"><hr></td>
                </tr>
              </table>
            </div>
			<br>
			<? } 
			
     ?></p>    
    </div>
    </div>
</div>
<div class="art-content-layout-br layout-item-0">
</div></div>


</article></div>
                    </div>
                </div>
            </div><footer class="art-footer">

<p>Copyright © <? echo $ano ?>. All Rights Reserved.</p>
</footer>

    </div>
    <p class="art-page-footer">
        <span id="art-footnote-links">Informatica Francisco Arias E.I.R.L.</span>
    </p>
</div>


</body></html>