<?php

    

    session_start();

    header("Content-Type: text/html; charset=UTF-8"); 

    require_once('../motormobil/motormobil.php');



?>

<?php

    require_once('../bussines/fix_characters.php');

$Obj_fix_characters = new fix_characters();



    require_once('../odbconexion/config.php');



?>

<?php

$Titulo_App='';

$Descripcion_Login_App='';

$Logo_APP='';

$Logo_Fav_Icon='';

$Id_Fk_Rol='';

$Titulo_Rol_Fk='';

try{    



    $Odbj_conexion = new odbconexion;

    $conexion=$Odbj_conexion->openconection();

    $consulta="SELECT * FROM configuracion_app_appquadrata JOIN rol_appquadrata ON configuracion_app_appquadrata.Id_Fk_Rol=rol_appquadrata.Id_Rol";

    $Array_adapter_config=$conexion->query($consulta);

    $conexion->close();

    while($Field_config=$Array_adapter_config->fetch_assoc())

    {   

        $Titulo_App=$Field_config['Titulo_App'];

        $Descripcion_Login_App=$Field_config['Descripcion_Login_App'];

        $Logo_APP=$Field_config['Logo_APP'];

        $Logo_Fav_Icon=$Field_config['Logo_Fav_Icon'];

        $Id_Fk_Rol=$Field_config['Id_Fk_Rol'];

        $Titulo_Rol_Fk=$Field_config['Titulo_Rol'];

    }

}catch (Exception $e) {

        echo 'Excepcion capturada: ',  $e->getMessage(), "

                    ";

}



//Declaramos la variable time, para que al modificar un archivo, este no se guarde en cache y se vizualicen los cambios

$time_log_assets=time();

/*inicializamos valores para la configuracion del template*/

$setting_template='../settings_template.txt';

$variables=[];

$_Color='';

$_Template='';

$_Theme_Template='';

$_Css='';

$_Js='';

if (file_exists($setting_template)) {

    $lines = file($setting_template, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);

    foreach ($lines as $line) {

        list($nombre_variable, $valor) = explode('=', $line);

        $variables[$nombre_variable] = $valor;

    }

    /*recogemos los valores de las variables*/

    if (isset($variables['Color'])) {

        $_Color = $variables['Color'];



        //echo "El color es: $_Color";

    }

    if (isset($variables['Template'])) {

        $_Template = $variables['Template'];

        //echo "El Template es: $_template";

    }

    if (isset($variables['Theme_Template'])) {

        $_Theme_Template = $variables['Theme_Template'];

        //echo "El Theme_Template es: $_Theme_Template";

    }

    if (isset($variables['css'])) {

        $_Css = $variables['css'];

        //echo "El css es: $_Css";

    }

    if (isset($variables['js'])) {

        $_Js = $variables['js'];

        //echo "El js es: $_Js";

    }

}

/*terminan valores de configuracion pára el template*/

?>

<!DOCTYPE html>

<html lang="en" class="light <?php if($_Color!=''){ echo 'theme-user'; }else{ echo $_Theme_Template; }?>">

    <!-- BEGIN: Head -->

    <head>

        <meta charset="utf-8">

        <?php

            if($Logo_Fav_Icon==''){

                echo "

                <link href=\"../dist/images/logo.svg\" rel=\"shortcut icon\" type=\"image/x-icon\" style=\"color:black;\">

                ";

            }else{

                try {

                    if (file_exists("../".str_replace('../','',$Logo_Fav_Icon))){

                        $time_icon=time();

                        $time_icon=filectime("../".str_replace('../','',$Logo_Fav_Icon));

                        echo "

                        <link href=\"../".str_replace('../','',$Logo_Fav_Icon)."?dummy=".$time_icon."\" rel=\"shortcut icon\">

                        ";

                    }else{

                        echo "

                        <link href=\"../dist/images/logo.svg\" rel=\"shortcut icon\" type=\"image/x-icon\" style=\"color:black;\">

                        ";  

                    }

                } catch (Exception $e) {

                    //echo "Ha ocurrido un error: " . $e->getMessage();

                }

            }

        ?>

        <meta name="viewport" content="width=device-width, initial-scale=1">

        <meta name="description" content="Desarrollado por SINAPSYS DEVOPS SA DE CV">

        <meta name="keywords" content="admin template, web app">

        <meta name="author" content="SINAPSYS">

        <title> <?=$Titulo_App;?> | Inicio de sesión</title>

        <!-- BEGIN: CSS Assets-->

        <link rel="stylesheet" href="../dist/css/<?=$_Css;?>?time=<?=$time_log_assets;?>" />

        <!-- END: CSS Assets-->

        <style type="text/css">

            body{

                /*background-color: white !important;

                height: auto !important;

                overflow-y:auto !important;*/

            }

             @media (min-width:1025px){

                .logo{

                    display: none;

                }

            }

            @media (max-width:1024px){



                .logo{

                    display: block !important;

                }

            }



        </style>

        <style>

        ::-webkit-scrollbar {

            display: none;

        }

        </style>

    </head>

        <?php 

        require_once('../logued.php');



            $error=!empty($_REQUEST['error'])?$_REQUEST['error']:'';

            $login=!empty($_REQUEST['login'])?$_REQUEST['login']:'';

            $intentos=!empty($_REQUEST['intentos'])?$_REQUEST['intentos']:0;

            $sessionactive = array_key_exists('login_appquadrata', $_SESSION) ? $_SESSION['login_appquadrata'] : '';

      

            if ($sessionactive==1) {

                if ($_SESSION['login_appquadrata']==1) 

                {

                    echo"<script language='javascript'>window.location='../home'</script>;";

                    exit();

                }

            }

            else

            {

                $cookieactive = array_key_exists('onstar_appquadrata', $_COOKIE) ? $_COOKIE['onstar_appquadrata'] : '';

                if ($cookieactive==1) {     

                    if ($_COOKIE['onstar_appquadrata']==1)

                    {

                        echo"<script language='javascript'>window.location='../login/secure/4c9184f37cff01bcdc32dc486ec36961.php?ee11cbb19052e40b07aac0ca060c23ee=$_COOKIE[tokenusu_appquadrata]&4c882dcb24bcb1bc225391a602feca7c=$_COOKIE[token_appquadrata]'</script>;";

                    }

                }

            }

        ?>

        

    <!-- END: Head -->

    <body class="login" onload="Queen_Guard();">

        <div class="container sm:px-10">

            <div class="block xl:grid grid-cols-2 gap-4">

                <!-- BEGIN: Login Info -->

                <div class="hidden xl:flex flex-col min-h-screen">

                    <a href="" class="-intro-x flex items-center pt-5">

                    </a>

                    <div class="my-auto">

                    	<?php 

	                    	if($Logo_APP==''){

		                        echo '<img alt="'.$Titulo_App.' - Admin Template" class="-intro-x w-1/2 -mt-16" src="../dist/images/illustration.svg">';

		                    }else{

		                        $time=time();

                                $time=filectime('../'.str_replace('../','',$Logo_APP));

		                    	echo '<img style="color:white;" alt="'.$Titulo_App.' - Admin Template" width="40%" class="-intro-x -mt-16"  src="../'.str_replace('../','',$Logo_APP).'?dummy='.$time.'"> ';

		                    }

	                    ?>

                        <div class="-intro-x text-white font-medium text-4xl leading-tight mt-10">

                            <?php

                            	//echo $Descripcion_Login_App;

                            ?>

                        </div>

                        <!--<div class="-intro-x mt-5 text-lg text-white text-opacity-70 dark:text-slate-400">Manage all your e-commerce accounts in one place</div>-->

                    </div>

                </div>

                <!-- END: Login Info -->

                <!-- BEGIN: Login Form -->

                

                <div class="h-screen xl:h-auto flex py-5 xl:py-0 my-10" style="overflow-y:visible !important; overflow-x:hidden !important;margin-top:auto !important;margin-bottom:auto !important;">

                    <div  class="my-auto mx-auto xl:ml-20 bg-white dark:bg-darkmode-600 xl:bg-transparent px-5 sm:px-8 py-8 xl:p-0 rounded-md shadow-md xl:shadow-none w-full sm:w-3/4 lg:w-2/4 xl:w-auto">

                        <center>

                        <?php

                            if($Logo_APP==''){

		                        echo '<img class="logo" alt="TUSABOGADOS - Admin Template" width="110" src="../dist/images/illustration.svg">';

		                    }else{

		                        $time=time();

                                $time=filectime('../'.str_replace('../','',$Logo_APP));

		                    	echo '<img class="logo" style="color:white;" alt="TUSABOGADOS - Admin Template" width="110"  src="../'.str_replace('../','',$Logo_APP).'?dummy='.$time.'">';

		                    }

		                    ?>

                        </center>

                        <h2 class="intro-x font-bold text-2xl xl:text-3xl text-center xl:text-left">

                            Crear cuenta

                        </h2>

                        <div class="intro-x mt-2 text-slate-400 xl:hidden text-center">

                        <?php

                        	//echo $Descripcion_Login_App;

                        ?>

                        </div>

                        <form style="margin-top: -30px" onsubmit="return checkSubmit();" action="../home/usuario/bussines/guardar" method="POST" id='frm'>

                        <div class="intro-x mt-12">

                        	<input type="hidden" name="action" value="registrar_externo">

                        	<input type="hidden" name="Id_Fk_Rol" value="<?=$Id_Fk_Rol;?>">

                        	<input type="hidden" name="Titulo_Rol_Fk" value="<?=$Titulo_Rol_Fk;?>">

                            <input type="text" class="intro-x login__input form-control py-3 px-4 block mt-4" placeholder="Apellido paterno *" name='Usu_Apaterno' id='Apellido_Paterno' required>

                            <input type="text" class="intro-x login__input form-control py-3 px-4 block mt-4" placeholder="Apellido materno *" name='Usu_Amaterno' id='Apellido_Materno' required>

                            <input type="text" class="intro-x login__input form-control py-3 px-4 block" placeholder="Nombre completo *" name='Usu_Nombre' id='Nombre' required>

                            <input type="tel" class="intro-x login__input form-control py-3 px-4 block mt-4" placeholder="Numero celular *" onkeypress='return event.charCode >= 48 && event.charCode <= 57' maxLength="10" minlength="10" name='Usu_Telefono' id='Numero_Celular' onblur="getRowsCelular(this.value);" required> 

                            	<p id='existeCelular' style="color:red;"></p>

                            <input type="email" class="intro-x login__input form-control py-3 px-4 block mt-4" placeholder="Correo *" name='Usu_Correo' id='Correo' onblur="getRowsEmail(this.value);" required>

                            <p id='existeEmail' style="color:red;"></p>

                            <input type="password" class="intro-x login__input form-control py-3 px-4 block mt-4" placeholder="Contraseña *" name='Usu_Password'  minlength="6" maxlength="12" id='Password' required>

                            <input type="password" class="intro-x login__input form-control py-3 px-4 block mt-4" placeholder="Confirmar contraseña *" minlength="6" maxlength="12" name="Confirm_Password" id='Confirm_Password' required>

                        </div>

                        <div class="intro-x flex items-center text-slate-600 dark:text-slate-500 mt-4 text-xs sm:text-sm">

                            <input id="remember-me" type="checkbox" class="form-check-input border mr-2" required>

                            <label class="cursor-pointer select-none" for="remember-me">Acepto los</label>

                            <a class="text-primary dark:text-slate-200 ml-1" href="">Terminos y condiciones</a>. 

                        </div>

                        <div class="intro-x mt-5 xl:mt-8 text-center xl:text-left">

                            <button class="btn btn-primary py-3 px-4 w-full xl:w-32 xl:mr-3 align-top">Continuar</button>

                            <a href="./" class="btn btn-outline-secondary py-3 px-4 w-full xl:w-32 mt-3 xl:mt-0 align-top">Iniciar sesión</a>

                        </div>

                        

                        </form>

                        <br>

                        <br>

                        <?php

                            if (strstr($error, "°")) 

                            { 

                                //catch error.

                                $messageerror="Verifica la información:";

                                        

                                if (strstr($error, "1")) 

                                {

                                    $messageerror=$messageerror." [Email no disponible.]";

                                }

                                if (strstr($error, "2")) 

                                {

                                    $messageerror=$messageerror." [Teléfono no disponible.]";

                                }

                                if (strstr($error, "3")) 

                                {

                                    $messageerror=$messageerror." [Cédula no disponible.]";

                                }

                                if (strstr($error, "4")) 

                                {

                                    $messageerror=$messageerror." [Ingresa correctamente tu contraseña]";

                                }

                                if (strstr($error, "5")) 

                                {

                                    $messageerror=$messageerror." [DATOS DE ACCESO INCORRECTOS VERIFICA: CORREO/TELÉFONO/CONTRASEÑA]";

                                }

                                echo "

                                <center>

                                    <div class='alert alert-danger alert-dismissable'>

                                        <strong Style='font-weight: 700;'>$messageerror</strong>

                                    </div>

                                </center>

                                ";

                            }

                        ?>

                    </div>

                </div>

                <!-- END: Login Form -->



            </div>

        </div>

        </div>

        <!-- END: Dark Mode Switcher-->

        

        <!-- BEGIN: JS Assets-->

        <script src="../dist/js/app.js"></script>

        <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>

        <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

        <script type="text/javascript">

        	/*document.addEventListener("DOMContentLoaded", function() {

			  document.getElementById("formulario-crear-cuenta").addEventListener('submit', validarFormulario); 

			});



			function validarFormulario(evento) {

			  evento.preventDefault();

			  var usuario = document.getElementById('usuario').value;

			  if(usuario.length == 0) {

			    alert('No has escrito nada en el usuario');

			    return;

			  }

			  var clave = document.getElementById('clave').value;

			  if (clave.length < 6) {

			    alert('La clave no es válida');

			    return;

			  }

			  this.submit();

			}*/

		function checkSubmit(){

             if($("#existeEmail").text()){

                alert("El número celular ingresado, se encuentra asociadoa una cuenta, intente con otro número.");

                statSend = true;

                return false;

             }else if($("#existeEmail").text()){



                alert("La dirección de correo electrónico ingresado, se encuentra asociado a una cuenta, intente con otro correo");

                statSend = true;

                return false;

             }else if($("#Password").val()!=$("#Confirm_Password").val()){

                alert("Sus contraseñas no coinciden, verifique e intente nuevamente");

                statSend = true;

                return false;

            }else if (!statSend) {

                statSend = true;

                return true;

            } else {

                alert('La Informaci\u00F3n ya se est\u00E1 enviando, por favor espere...');

                return false;

            }

            statSend = true;

            return false;

		}

function validaNumericos(event) {

    if(event.charCode >= 48 && event.charCode <= 57){

      return true;

     }

     return false;        

}

		function getRowsEmail(email){  

	        $.ajax({

	            url: './ajax.php',

	            type: "POST",

	            data: {action:'email',email:email},

	            success: function (data) {

	                var rows=eval(data);

	                if(rows>=1){

	                	$("#existeEmail").html("!Lo sentimos, esta dirección de correo electrónico ya se encuentra asociada a una cuenta, intente con otro correo diferente!");

	                }else{

						$("#existeEmail").html("");

	                }

	            }

	        });

	    }

        function getRowsCelular(celular){  

	        $.ajax({

	            url: './ajax.php',

	            type: "POST",

	            data: {action:'celular',celular:celular},

	            success: function (data) {

	                var rows=eval(data);

	                if(rows>=1){

	                	$("#existeCelular").html("!Lo sentimos, este número ya se encuentra asociada a una cuenta, intente con otro número diferente!");

	                }else{

						$("#existeCelular").html("");

	                }

	            }

	        });

	    }

        </script>

        <!-- END: JS Assets-->

    </body>

</html>



