<?php
session_start();
include("cls_conexion.php");$CNN=new ClsMySQL();include("conexion23.php");
//
if(strlen($_SESSION['SYS_USER_ID'])==0){JsDir("login.php");	return;}
//
include("deos_pre_plantilla4_bx.php");
//
if($StrCmd=="G"){
	$z="SELECT ID FROM vproductos WHERE $FF ORDER BY LINEA,MODELO,DESCRIPCION";
	$z=PagSql($z,$LStrPag,$VP_RegXPag,$LStrTR);						
	$rs = grs($z);
	while ($r = $rs->fetch_assoc()){
		$_COD=V($_POST["C_".$r['ID']]);
		$_IMG=V($_FILES["I_".$r['ID']]['name']);			
		//
		$s="UPDATE productos SET pro_codigo='$_COD' WHERE id_producto=".$r['ID'];
		ejt($s);
		//
		if(strlen($_IMG)>0){				
			if(strlen($_COD)>0){
				$FActual=ImgA("fotos/pro".$r['ID']);
				ImgE($FActual);
				
				$_FN="fotos/pro".$r['ID'].".png";
				move_uploaded_file($_FILES["I_".$r['ID']]['tmp_name'], $_FN);
				
			}
		}
		//
	}
	$StrMsg="onload=\"alert('Datos actualizados')\";";
}

$IdUsu=$_SESSION['SYS_USER_ID'];
$AT=gs("at","usuarios","id_usuario=$IdUsu");
?>



<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Actualizar codigo e imagenes</title>
<!--INI_SCRIPT------------------------------------------------------------------------------>
<?php AddJs(); ?>
<script type="text/javascript" src="ja/funciones.js"></script>
<!--FIN_SCRIPT------------------------------------->
<link rel="stylesheet" type="text/css" href="css/estiloss.css"  />
<link rel="stylesheet" type="text/css" href="css/basic.css"  />
<link rel="stylesheet" type="text/css" href="css/mnu.css"  />

<style type="text/css">
.cF {height:600px;width:1250px;position:relative;top:0px}
.mM {height:34px;width:1250px;position:relative;top:0px;background-color:#09C; z-index:500;}

</style>
<script>
$(document).ready(function(){  
   Inicializar();
   jF("TxtCod");
});
</script>

<script>

function fGuardar(){
	

	if(pre("Esta seguro que desea guardar")){

	//
	frm = document.getElementById("Frm");
	//
	for(i=0; i<frm.elements.length; i++){
		var t=frm.elements[i].type;
		if (t=="text"){
			var n=frm.elements[i].name;
			var cod=n.indexOf("C_");		
			if(cod>=0){
				frm.elements[i].style.backgroundColor="#FFFFFF";
			}
		}
	}
	//
	for(i=0; i<frm.elements.length; i++){
		var t=frm.elements[i].type;
		if (  t=="file" ){			
			var StrF=frm.elements[i].value;
			var StrN=frm.elements[i].name;
			var StrI=StrN.split("_");
			var StrT="C_"+StrI[1];
			if(jLen(StrF)>0){
				StrF=StrF.toUpperCase();
				var png=StrF.indexOf(".PNG");		
				if(png==-1){
					document.getElementById(StrT).style.backgroundColor="#EBC851";	
					frm.elements[i].value="";
					alert("Solo se permite imagenes de los siguientes formatos .png ");
					frm.elements[i].focus();
					return;
				}
				//
				var F11=frm.elements[i];
				var StrFile = F11.files[0];
				if(StrFile.size>80*1024){
					document.getElementById(StrT).style.backgroundColor="#EBC851";	
					frm.elements[i].value="";
					alert("El tamaño del archivo no debe ser superior a 80Kb");
					frm.elements[i].focus();
					return;
				}
				//
			}
		}		
	}
	//

		SM("G");
	}
}

$(document).keydown(function(e){
	var AT=gv("TxtAT");

	if(e.which==66 && e.altKey){
		if(AT=="1"){	
		document.getElementById("CmdB").click();
		return;
		}
	}

	if(e.which==86 && e.altKey){
		if(AT=="1"){
		document.getElementById("CmdZ").click();
		return;
		}
	}
	
	if(e.which==71 && e.altKey){		
		if(AT=="1"){	
		document.getElementById("CmdG").click();
		return;
		}
	}
  
});
</script>
</head>

<body  <?php echo $LStrMsg;?>>
<div align="center">

<div class="mM" align="left" style="font-size:12px">
<?php
$HTM=file_get_contents("http://inversionessounduniversal.com/ventas/phpmnu.php?USER_ID=$IdUsu");
echo $HTM;
?>
</div>

<div Id="DivFRM"  class="cF" style="background-color:#FFFFFF;">
<form id="Frm" name="Frm" method="post" action="pre_plantilla4.php" 
enctype="multipart/form-data" style="margin:0px; padding:0px; display:inline;" onSubmit="return false;">

<!----------------------------------------->
<div id="DivT" class="dT"  style="width:1250px;">
<img src="b.png" class="iT" />
<div class="tT">ACTUALIZAR CODIGOS - IMAGENES</div>
</div>

<!----------------------------------------->
 
<div class="s1" style="left: 35px; top: 117px; width: 52px;">CODIGO</div>
<input name="TxtCod" type="text" id="TxtCod" 
class="lt" style="left: 35px; top: 135px; width: 106px" 
value="<?php echo $StrCod;?>"  
tabindex="<?php echo ++$TI;?>"/>

<div class="s1" style="left: 150px; top: 117px; width: 136px;">
LINEA DE PRODUCTO</div>
<select name="CboLin" id="CboLin" 
class="lt" style="left: 150px; top: 135px; width: 177px"
tabindex="<?php echo ++$TI;?>">
<?php echo FCBO_("lin_nombre","lineas","id_linea>0",$StrLin,"S","");?>
</select>

<div class="s1" style="left: 338px; top: 117px; width: 94px;">
FABRICANTE</div>
<select name="Fab" id="Fab" 
class="lt" style="left: 338px; top: 135px; width: 198px" 
tabindex="<?php echo ++$TI;?>">
<?php echo FCBO_("fab_nom","fabricantes","id_fab>0",$Fab,"S","N");?>
</select>

<div class="s1" style="left: 548px; top: 117px; width: 120px;">
MODELO</div>
<select name="Mod" id="Mod" 
class="lt" style="left: 545px; top: 135px; width: 177px" 
tabindex="<?php echo ++$TI;?>">
<?php echo FCBO_("mod_nom","modelos","id_mod>0",$Mod,"S","N");?>
</select>

<div class="s1" style="left: 731px; top: 117px; width: 143px;">
DESCRIPCION</div>
<input name="TxtDes" type="text" id="TxtDes" 
class="lt" style="left: 728px; top: 135px; width: 240px" 
value="<?php echo $StrDes;?>"  
tabindex="<?php echo ++$TI;?>" />

<div class="s1" style="left: 980px; top: 117px; width: 125px;">
MARCA</div>
<select name="CboMar" id="CboMar" 
class="lt" style="left: 980px; top: 135px; width: 195px" 
tabindex="<?php echo ++$TI;?>">
<?php echo FCBO_("mar_nombre","marcas","id_marca>0",$StrMar,"S","");?>
</select>

<!----------------------------------------->
<div id="DivBtn" align="left" style="position:absolute; left: 33px; top: 71px; width: 551px; height: 26px;">
<input name="CmdB" type="button" id="CmdB" class="btm"
value="Buscar" onClick="fFiltrar();"  
tabindex="<?php echo ++$TI;?>" />

<input name="CmdG" type="button" id="CmdG" class="btm"
value="Guardar" onClick="fGuardar();" 
tabindex="<?php echo ++$TI;?>"/>

</div>
<!-----------------------------------------> 

<div class="datagrid" style="position: absolute; left: 35px; top: 165px; width: 1180px; height: 400px; overflow: auto">
<table width="75%">
<thead>
<tr>
<td colspan="13" align="center"><?php echo PagBtn($LStrTR,$VP_RegXPag,$LStrPag);?></td>
</tr>

<tr>
<th width="11%">CODIGO</th>
<th width="15%">LINEA</th>
<th width="14%">MODELO</th>
<th width="33%">DESCRIPCION</th>
<th width="24%">IMAGEN</th>
<th width="3%">IMG</th>
</tr>
</thead>
<tbody>

<?php		  		
$s="SELECT ID,COD,
	SUBSTRING(LINEA,1,23) AS LINEA,
	SUBSTRING(MODELO,1,23) AS MODELO,
	SUBSTRING(DESCRIPCION,1,50) AS DESCRIPCION,FAB
	FROM vproductos WHERE $FF ORDER BY LINEA,MODELO,DESCRIPCION ";
	$s=PagSql($s,$LStrPag,$VP_RegXPag,$LStrTR);						
	$rs = grs($s);
	while ($r = $rs->fetch_assoc()){
		$_COD="C_".$r['ID'];
		$_IMG="I_".$r['ID'];
		$COD=$r['COD'];
		$IMG=GET_IMG($COD);
		?>
		<tr>
		<td bgcolor="#FFFFFF">
        <input name="<?php echo $_COD;?>" class="lt" 
         value="<?php echo $r['COD'];?>" 
         type="text" id="<?php echo $_COD;?>"
         style="position:inherit; width:120px;" 
         tabindex="<?php echo ++$TI;?>"/>
        </td>
		<td bgcolor="#FFFFFF"><?php echo $r['LINEA'];?></td>
		<td bgcolor="#FFFFFF"><?php echo $r['MODELO'];?></td>
		<td bgcolor="#FFFFFF"><?php echo $r['DESCRIPCION'];?></td>
		<td bgcolor="#FFFFFF">
        <input name="<?php echo $_IMG;?>" type="file"
        id="<?php echo $_IMG;?>" style="position:inherit"/>
        </td>
		<td bgcolor="#FFFFFF">
        <a href="#"  onclick="window.open('productos.php?Id=<?php echo $r['ID'];?>', '_blank');">  <img src="<?php echo ImgA("fotos/pro".$r['ID']); ?>" width="12" height="18" /></a></td>
		</tr>

		<?php
	}
?>		  
</tbody>
</table>
</div>

<!----------------------------------------->    
<?php include("ocultos.php");?>

</form>
</div>
</div>
</body>
</html>
