<?php
 session_start();
 include "emenux.php";
 //------INI-Coneccion Local
 require ("conecta.php"); 
 //------INI-Coneccion Local
 //Recibe descripcion
 $sw=$_POST['hdsw'];
 $descripcio=$_POST['descripcio'];
 $nicksin=$_SESSION['nick'];
 $sqlb="SELECT * from m02004 where llave='$nicksin';";
 $resb=mysql_query($sqlb,$con);
 // contador de resultados en "0";
 $cant=0;
 //desmarcamos todos los articulos del usuario
 $sqlbm="update m02004 set estado='0' where llave='$nicksin';";
 $resbm=mysql_query($sqlbm,$con) or die(mysl_error());
 if (mysql_num_rows($resb)>0){
   while ($filab = mysql_fetch_row($resb)){    
    $cant++;
   }//while
  }//fin si
 if ($sw=="eliminar"){
  $nick=$_SESSION['nick'];
  $totalf=$_POST['hdcont'];
  for ($i=1;$i<=$totalf;$i++){
   $icheck="check" . $i;
   $check[$i]=$_POST[$icheck];
   $icodigo="hd" . $i;
   $icant="hdcant" . $i;
   $cantidad=$_POST[$icant];
   $codigo[$i]=$_POST[$icodigo];
   if($check[$i]=="checkbox"){
    $code=$codigo[$i];
    $sqle="delete  from m02004 where cod_interno='$code' and llave='$nick' and cantidad='$cantidad' limit 1;";
    $rese=mysql_query($sqle,$con) or die(mysql_error());
   }
  }//for
  $sw="";
 }//fin eliminar
 if ($cant<1){
  mysql_close($con);
  header("Location: http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . "/M0205001.php" );
 }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>

<TITLE>Carro de Compra</TITLE>

<link rel="stylesheet" href="styles.css">
<style type="text/css">
<!--
.Estilo1 {
	color: #FFFFFF;
	font-weight: bold;
}
-->
</style>
<script language="javascript">
function valida(){
 document.form1.action="M0205002.php";
 document.form1.method="post";
 document.form1.submit();
}
function Sel(n){ 
 document.form1.hdrdbut.value=n;
 document.form1.vender.disabled=false;
// window.alert(document.form1.hdrdbut.value);
} 
function eliminar(){
 document.form1.hdsw.value="eliminar";
 document.form1.submit();
}
function chk(){
 <?php
 for ($i=1;$i<=$cant;$i++){ 
 echo "document.form1.check$i.checked=document.form1.checkbox.checked;";
 }
 ?>  
}//chk
function enviaprueba(){
 document.form1.action="prueba.php";
 document.form1.method="post";
 document.form1.submit();
}
function cotizacion(usuario){
 window.open("cotizacion.php?usuario=" + usuario);
}
function recupera(){
 var numero=new String;
 numero=prompt("ingrese numero de cotización");
 document.form1.hdcot.value=numero;
 document.form1.action="recuperacot.php";
 document.form1.method="post";
 document.form1.submit();
}
</script>

</HEAD>
<BODY>
<TABLE height="100%" cellSpacing=0 cellPadding=0 width="100%" align=center 
border=0>
  <TBODY>
  <TR>
    <TD vAlign=center align=middle height="100%">
      <TABLE height=400 cellSpacing=0 cellPadding=0 width=718 border=0>
        <TBODY>
        <TR>
          <TD width="718" height=22>
            <TABLE height=22 cellSpacing=0 cellPadding=0 width="100%" 
              border=0><TBODY>
              <TR>
                <TD vAlign=top align=left width=24><A 
                  href="index.php"><IMG 
                  height=22 src="images/xc_left.gif" width=24 
                  border=0></A></TD>
                <TD vAlign=top align=left width="100%"><IMG height=22 
                  src="images/xc_center.gif" width="100%" 
                border=0></TD>
              <TD vAlign=top align=right width=24><IMG height=22 
                  src="images/xc_right.gif" width=24 
              border=0></TD></TR></TBODY></TABLE></TD></TR>
        <TR>
          <TD class=BottomTable vAlign=top 
          background=images/xc_stripes.gif height="100%">
            <TABLE class=IconsTable height=33 cellSpacing=0 cellPadding=0 
            width="100%" border=0>
              <TBODY>
              <TR>
                <TD height="32"><div align="right" class="larger">
                  <div align="right">&nbsp;&nbsp;Vemol</div>
                </div></TD>
                </TR></TBODY></TABLE>
            <TABLE width="715" 
              border=0 cellPadding=0 cellSpacing=0 bordercolor="#595959">
              <TBODY>
              <TR>
                <TD width=23 height=18>&nbsp;</TD>
                <TD height=18 align=left vAlign=top><div align="right"><a href='javascript:recupera()'>Recuperar Cotizaci&oacute;n</a> </div></TD>
                <TD width=20 height=18>&nbsp;</TD></TR>
              <TR>
                <TD width=23 height="100%">&nbsp;</TD>
                <TD height="100%" align=left vAlign=top><form id="form1" name="form1" method="post" action="carro.php">
                  <table width="100%" border="1" cellpadding="0" cellspacing="0">
                      <tr>
                        <td colspan="6" scope="col"><div align="center" class="LeftMenu"><strong><span class="MainMenuHead"></strong><label>
                          <input name="elimin" type="button" id="elimin" value="Eliminar Items" onclick="eliminar()" />
                          </label>
                          <label></label>
                          <input name="hdsw" type="hidden" id="hdsw" />
                          <label></label>
                          
                          <label>
                          &nbsp;&nbsp;
						  <label>
						   <input name="radiobutton" type="radio" value="radiobutton" onclick="Sel('01')"  />
						   Factura
						  </label>
						  <label>
						   <input name="radiobutton" type="radio" value="radiobutton" onclick="Sel('02')"/>
						   Boleta
						  </label>
						  <label>
						   <input name="radiobutton" type="radio" value="radiobutton" onclick="Sel('03')"/>
						   Guia despacho
						  </label>
						   <label>
						   <input name="radiobutton" type="radio" value="radiobutton" onclick="Sel('04')"/>
						   Guia Interna
						  </label>
	  					 &nbsp;
	  					 <input name="hdrdbut" type="hidden" id="hdrdbut" />
<input name="vender" type="button" id="vender" value="Vender" disabled="disabled" onclick="valida()" />
                        <input name="cotizar" type="button" id="cotizar" value="Cotizar" onclick="cotizacion('<?php echo $_SESSION['nick']  ?>')"; />
                        </div></td>
                        </tr>

                      <tr>
                        <td width="10%" class="m0l0oout Estilo1" scope="row"><div align="left">Item
                          <input name="checkbox" type="checkbox" value="checkbox"  onclick="chk()" />
                        </div></td>
                        <td width="9%" class="m0l0oout Estilo1" scope="row"><div align="left">Cantidad</div></td>
                        <td width="13%" class="m0l0oout" scope="row"><div align="center" class="Estilo1">
                          <div align="left">Cod_interno</div>
                        </div></td>
                        <td width="44%" class="m0l0oout Estilo1" scope="row"><div align="left">Glosa</div></td>
                        <td width="12%" class="m0l0oout Estilo1" scope="row"><div align="left">Precio</div></td>
                        <td width="12%" class="m0l0oout" scope="row"><div align="left" class="Estilo1">Total</div></td>
                      </tr>
					  <?php
					   //Definimos los colores a usar
					   $color0 = "#A4B4C1";
					   $color1 = "#D5E7FB";
					   $color2 = "#E8F2FC";
					   $color3 = "#E0FAC5";
					   $color = $color1;
					   $contf=0;
					   $resb=mysql_query($sqlb,$con);					   
					   if (mysql_num_rows($resb)>0){
					    while ($filab = mysql_fetch_row($resb)){
						$contf++;
						$ncheck="check" . $contf;
						$nhd="hd" . $contf;
						$nhdcant="hdcant" .$contf;
						$nhdpre="hdpre". $contf;
						$canti=$filab[5];
						$codin=$filab[1];
						$glosa=strtoupper($filab[3]);
						$preci=$filab[6];
						$stota=$filab[7];
						 // empezando una tabla html
						 echo "<tr style=\"background-color:$color\" onMouseOver=\"this.style.backgroundColor='$color3'\" onMouseOut=\"this.style.backgroundColor='$color'\">";
						 echo "<td><center><input type='checkbox' name='$ncheck' value='checkbox' /></center></td>";
						 echo "<td align='right'>$canti <input type='hidden' name='$nhdcant' id='$nhdcant' value='$canti'/></td>";
						 echo "<td>$codin <input type='hidden' name='$nhd' id='$nhd' value='$codin'/></td>";
						 echo "<td>$glosa</td>";
						 echo "<td align='right'>$preci <input type='hidden' name='$nhdpre' id='$nhdpre' value='$preci'/></td>";
						 echo "<td align='right'>$stota</td>";
						 echo "</tr>";
						 if ($color == $color1){
						  $color = $color2;
						  }else{
						  $color = $color1;
						 }
						}//while
					   }//fin si 
					  ?>
                      <tr>
                        <td colspan="6" scope="row"><label>
                          <label><span class="LeftMenu"><strong>Item dentro del Carro :<?php echo $cant ?></strong> </span></label>
                          <div align="center" class="LeftMenu"><acronym><a href="M0205001.php">Volver a Buscar </a></acronym>
                            <input type="hidden" name="hdcont" id="hdcont" value=<?php echo $contf ?> />
                            <label></label>
                            <input type="hidden" name="hdcot" id="hdcot" />
                          </div>
                          <span class="LeftMenu">
                          <label></label>
                          </span></td>
                        </tr>
                      <tr>
                        <th colspan="6" scope="row"><label></label></th>
                        </tr>
                    </table>
                </form>
                  <p>&nbsp;</p>                  <p><a href="buscar"></a> </p></TD>
                <TD width=20 height="100%">&nbsp;</TD></TR>
              <TR>
                <TD width=23 height=8>&nbsp;</TD>
                <TD height=8>&nbsp;</TD>
                <TD width=20 
      height=8>&nbsp;</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></TD></TR></TBODY>
	  <script language="JavaScript" src="menu.js"></script>
<script language="JavaScript" src="menu_tpl.js"></script>
<script language="JavaScript">
	new menu (MENU_ITEMS, MENU_POS);
</script>
	  </TABLE>
	</BODY>
<?php
 //------FIN-Coneccion Local
 mysql_close($con)
 //------FIN-Coneccion Local
 ?>
</HTML>