<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DMMYSQLG.php");
require_once("DF80000.php");
?>
<html>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<script language="javascript">
function envFormVal(){
	tecla = (document.all) ? event.keyCode : event.which; 
	if(tecla==8) return true; //Tecla de retroceso (para poder borrar) 
	if(tecla==13){
		//alert('entra');
		document.getElementById('valida').click();
		return false;
	}else{
		return true;
	}
}
</script>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>

<body>
<?php
 
$ayuda = 'DG3000A_PR.php';
include("DYAYUDA.php");
?>
<?php

if(isset($_POST['valida'])){
	$pwd=$_POST['password'];
	$idVen=$_POST['vendedor'];
	$tipVen=$_POST['tip_caj'];
	$sq_catven=mysqli_query($con ,"SELECT * FROM dgcatven WHERE cod_ven='$idVen' AND pasw='$pwd'");
	@$dt_tipven=mysqli_fetch_array(mysqli_query($con ,"SELECT * from dgtipven where tip_ven='$tipVen'"));
	if(mysqli_num_rows($sq_catven)>0){
		$dt_catven=mysqli_fetch_array($sq_catven);
		$_SESSION['vendedor'] = $dt_catven['cod_ven'];
		$_SESSION['tipven'] = $tipVen;
		$_SESSION['al']=$dt_tipven['almacen'];
		$_SESSION['tipven2'] = 1;
		$_SESSION['tipven1'] = "";
		$_SESSION['password'] = $dt_catven['pasw'];
		$_SESSION['opeven'] = 2;
		$_SESSION['repmen1'] = "";
		$_SESSION['repmen2'] = "";
		echo '<script languaje="javascript">window.parent.leftFrame.location.reload();</script>';
		//echo '<meta content="0; url=MENU_ADM.php"  HTTP-EQUIV="REFRESH">';	
		exit();
	}
	else{
		echo '<h2>&iexcl;&iexcl;&iexcl; CLAVE INCORRECTA !!!</h2>';
		echo '<meta content="1; url=DG30000_PR.php" HTTP-EQUIV="REFRESH">';
		exit();
	}
}
else{
	$_SESSION['tipven'] = "";
	$_SESSION['vendedor'] = "";
	$_SESSION['password'] = "";
}
?>
<form name="frm1" id="frm1" method="post" action="" target="_self">
  <table  align="center">
    <tr>
      <th colspan="2">ACCESO A CAJA FACTURACION </th>
    </tr>
    <tr>
      <td class="estilotabla Estilo7 Estilo9">Cajero:</td>
      <td class="estilotabla"><span class="Estilo10">
        <select name="vendedor" id="vendedor" onChange="openpage('DG30000_PR.php','_self');">
          <?php

		@$resultado=mysqli_query($con ,"select * from dgcatven WHERE tip_per='C' OR tip_per='VC' order by nom_ven");
		if(!isset($_POST['vendedor'])){
			$dt_catven=mysqli_fetch_array($resultado);
			$selVen=$dt_catven['cod_ven'];
			if(mysqli_num_rows($resultado)>0)
				mysqli_data_seek($resultado,0);
		}
		else{
			$selVen=$_POST['vendedor'];
		}		
		while($registro=mysqli_fetch_array($resultado)){
			if($selVen==$registro['cod_ven'])
				echo '<option value="' . $registro['cod_ven'] . '" selected>' . $registro['nom_ven'] . ' ' . $registro['ap_pat_ven'] . ' ' . $registro['ap_mat_ven'] . '</option>';
			else
				echo '<option value="' . $registro['cod_ven'] . '">' . $registro['nom_ven'] . ' ' . $registro['ap_pat_ven'] . ' ' . $registro['ap_mat_ven'] . '</option>';
		}			
		?>
        </select>
      </span></td>
    </tr>
    <tr>
      <td class="estilotabla Estilo7 Estilo9">Password:</td>
      <td class="estilotabla">
	  <input name="password" type="password" id="password" onKeyPress="return envFormVal();" value=""></td>
    </tr>
    <tr>
      <td class="estilotabla Estilo7 Estilo9">Tipo de venta:</td>
      <td class="estilotabla"><span class="Estilo10">
        <select name="tip_caj" id="tip_caj" >
          <?php

		  	@$dt_catven=mysqli_fetch_array(mysqli_query($con ,"select * from dgcatven where cod_ven='$selVen'"));
			@$resultado=mysqli_query($con ,"select * from dgtipven") or die ("Consulta inv&aacute;lida");
			while($registro=mysqli_fetch_array($resultado)){
				if(strstr($dt_catven['aceso'],$registro['tip_ven']))
					echo '<option value="' . $registro['tip_ven'] . '">' . $registro['des_tipven'] . '</option>';
			}			
		?>
        </select>
      </span></td>
    </tr>
    <tr>
      <td class="estilotabla Estilo7 Estilo9">Fec. Mov.: </td>
      <td class="estilotabla Estilo7 Estilo9"><?php

	  $fecCor=date('Y-m-d');
	  $dt_cajsalHoy=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM dgcajsal WHERE  fec_cor='$fecCor' "));
	  if($dt_cajsalHoy['cor_dia']){
	  	$fecCor=addDay($fecCor,1);
	  }
	  echo chfecha($fecCor,'Y-m-d','d/m/Y');
	  $_SESSION['fecven']=$fecCor;
	  
	  ?>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2"><div align="center">
          <input name="valida" type="submit" id="valida"  value="Entrar"/>
      </div></td>
    </tr>
  </table>
</form>


</body>
</html>
