<?php 
include "dbconection.php";


if(isset($_REQUEST['origen'])){
    
	$query = "SELECT * FROM tblusuariosrutas WHERE strPassword='".$_REQUEST['txtUserPassword']."'";

	$queryResult = mysql_query($query);			
	$totalRows = mysql_num_rows($queryResult);
			
	if($totalRows > 0){
		echo "true";
	}else{
		echo "false";
	}

}else{
    
    if( isset($_REQUEST['txtCuenta']) && isset($_REQUEST['txtContrasena']) ){
		$strUsuario = $_REQUEST['txtUser'];
		$strPass = $_REQUEST['txtUserPassword'];		
	}


	//$bEncontroSimboloIgual1 = instr(1, Usuario, "=", vbtextcompare)
	$bEncontroSimboloIgual1 = strpos($strUsuario, "=");
	$bEncontroSimboloIgual2 = strpos($strPass, "=");

	$bEncontroDrop1 = strpos($strUsuario, "drop "); 
	$bEncontroDrop2 = strpos($strPass, "drop "); 

	//if( $bEncontroSimboloIgual1>0 || $bEncontroSimboloIgual2>0 || $bEncontroDrop1>0 || $bEncontroDrop2>0 ){
	if( $bEncontroSimboloIgual1!==false || $bEncontroSimboloIgual2!==false || $bEncontroDrop1!==false || $bEncontroDrop2!==false ){
			header("Location: index.php?leyenda=1.1");
			exit();
	}


	$query = "SELECT t1.* FROM tblusuariosrutas t1 
	WHERE t1.strLogin='". $strUsuario ."' AND t1.strPassword='". $strPass ."'";
	//exit( $query );

	$queryResult = $mysqli->query($query);

	if(mysqli_num_rows($queryResult)>0){
		$row = mysqli_fetch_assoc($queryResult);
		session_start();
		
		$_SESSION['user_id'] = $row['intUsuario'];
		$_SESSION['user_name'] = $row['strNombre'];
		$_SESSION['user_login'] = $row['strLogin'];
		
		$intTipo = intval($row['intTipo']);
		
		$_SESSION['user_type'] = $intTipo;
		$_SESSION['str_type'] = $strTipo;

		if($intTipo==1){
		    $strTipo =  "Administrador";  
		    //header("Location: sistema.php?omar=190280");
		    header("Location: app.php?#dashboard&omar=190280");

		}else if($intTipo==2){
		    $strTipo =  "Socio Vendedor"; 
		    //header("Location: ruta.php?omar=190280");
		    header("Location: ruta.php?#ruta&omar=190280");

		/*}else if($intTipo==3){
		    $strTipo =  "Monitor Tv";  
		}else if($intTipo==4){
		    $strTipo =  "Enfermera";  
		    */
		}
		 

	}else{
		header("Location: index.php?Leyenda=1");
	}
}
?>