<?php require "php/cabecera3.inc";
	
	if(isset($_SESSION['usuario'])){
		echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php?IDS=$IDS'>";
		exit();
	}
	$form="<br><br><CENTER><TABLE><form action='log.php' method='post'>
	<TR><TD><input type='text' name='email' placeholder='E-Mail' required='required' maxlength='30'></TD></TR>
	<TR><TD><input type='password' name='passw' placeholder='Contraseña' required='required' maxlength='15'></TD></TR>
	<input type='hidden' name='IDS' value='$IDS'>
	<input type='hidden' name='respuesta' value='1'>
	<TR><TD><CENTER><input type='submit' class='btn' STYLE='float:center;' value='Ok'><CENTER></TD></TR>			
	</form></TABLE></CENTER>";
	
	$err="<script>alert('Datos inválidos')</script>";
	
	if(isset($_POST['respuesta'])){
		$usrdat = mysqli_query($conexion,"SELECT * FROM ecomm_usuarios WHERE EMAIL='$_POST[email]'");
		if (mysqli_num_rows($usrdat)>0){
			$datos= mysqli_fetch_array($usrdat);
			if($datos['EMAIL']==$_POST['email']){
				if($datos['PASS']==sha1($_POST['passw'])){
					$_SESSION['usuario']=$datos['ID'];
					echo "<META HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php?IDS=$IDS'>";
				}
				else{echo $err.$form;}
			}
			else{echo $err.$form;}
		}
		else{echo $err.$form;}
	}
	else{
		echo $form;
	}

	require "php/pie.inc";
?>