<?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='';

$Habilitar_Formulario_Registro='';

try{    



    $Odbj_conexion = new odbconexion;

    $conexion=$Odbj_conexion->openconection();

    $consulta="SELECT * FROM configuracion_app_appquadrata";

    $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'];

        $Habilitar_Formulario_Registro=$Field_config['Habilitar_Formulario_Registro'];

    }

}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="es" 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;?>" />

        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

        <!-- END: CSS Assets-->

        <style type="text/css">



             @media (min-width:1025px){

                .logo{

                    display: none;

                }

            }

            @media (max-width:1024px){



                .logo{

                    display: block !important;

                }

            }



             .input-container {

                position: relative;

                display: flex;

              }

            .input-container .icon {

                z-index: 50;

                position: absolute;

                left: 12px;

                top: 53%;

                transform: translateY(-50%);

                cursor: pointer;

            }



            .input-container .icon2 {

                z-index: 50;

                position: absolute;

                left: 12px;

                top: 62%;

                transform: translateY(-50%);

                cursor: pointer;

            }



            .input-container input[type="text"],

            .input-container input[type="password"],

            .input-container input[type="tel"],

            .input-container input[type="email"] {

                padding-left: 35px;

            }



        </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='/appquadrata/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='/appquadrata/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.'"> ';

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

		                    }

	                    ?>

                        <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 xl:my-0">

                    <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="'.$Titulo_App.' - 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="'.$Titulo_App.' - 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">

                            Inicio de sesión

                        </h2>

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

                        <?php

                        	echo $Descripcion_Login_App;

                        ?>

                        </div>

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

                            <form onsubmit="return checkSubmit();" action="secure/5429f3372b0043170951d52ba8def05e.php" method="POST">

                            <div class="input-container">

                                <span id="icon_user" class="icon" onclick="toggleInputType()"><i class="fa fa-at" style="font-size:15px"></i></span>

                                <input type="tel" id="inputField" class="intro-x login__input form-control py-3 px-4 block" placeholder="Ingrese su teléfono" name="ee11cbb19052e40b07aac0ca060c23ee" value="<?php echo $login; ?>" required>

                            </div>

                            <div class="input-container">

                                <span id="icon_password" class="icon2" onclick="togglePasswordType()"><i class="fa fa-eye-slash" style="font-size:15px"></i></span>

                                <input id="inputPassword" type="password" class="intro-x login__input form-control py-3 px-4 block mt-4" placeholder="Contraseña" id='4c882dcb24bcb1bc225391a602feca7c' name="4c882dcb24bcb1bc225391a602feca7c" required>

                            </div>

                        </div>

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

                            <div class="flex items-center mr-auto">

                                <div class="flex flex-col sm:flex-row items-center p-5 border-b border-slate-200/60 dark:border-darkmode-400">

                                    <div class="form-check form-switch w-full sm:w-auto sm:ml-auto mt-3 sm:mt-0">

                                        <label class="cursor-pointer select-none" for="sesionup"> Mantener la sesión iniciada 

                                        <input type="checkbox"  class="show-code form-check-input mr-0 ml-3" value="1" name="sesionup" id="sesionup" checked>

                                        </label>

                                    </div>

                                </div>

                            </div>

                            <!--<a href="">Forgot Password?</a>--> 

                        </div>

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

                            <a href="./recovery.php" style="color:blue;">¿Olvidaste tu contraseña?</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">Iniciar Sesión</button>

                             <?php if($Habilitar_Formulario_Registro=='Si'){ ?>

                                <a href='crear-cuenta' class="btn btn-outline-secondary py-3 px-4 w-full xl:w-64 mt-3 xl:mt-0 align-top">Crear cuenta</a>

                            <?php } ?>

                        </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>

                                ";

                            }

                        ?>

                        <!--aqui termina los campos del formulario-->

                        <!--<div class="intro-x mt-10 xl:mt-24 text-slate-600 dark:text-slate-500 text-center xl:text-left"> By signin up, you agree to our <a class="text-primary dark:text-slate-200" href="">Terms and Conditions</a> & <a class="text-primary dark:text-slate-200" href="">Privacy Policy</a> </div>-->

                    </div>

                </div>

                <!-- END: Login Form -->



            </div>

        </div>

        </div>

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

        

        <!-- BEGIN: JS Assets-->

        <script>

            function toggleInputType() {

              var inputField = document.getElementById('inputField');

              var icon = document.getElementById("icon_user");



              if (inputField.type === 'tel') {

                inputField.type = 'email';

                inputField.placeholder = 'Ingrese su correo electrónico';

                icon.innerHTML = '<i class="fa fa-mobile-phone" style="font-size:24px"></i>';

              } else {

                inputField.type = 'tel';

                inputField.placeholder = 'Ingrese su teléfono';

                icon.innerHTML = '<i class="fa fa-at" style="font-size:15px"></i>';

              }

              inputField.value='';



              inputField.focus();

            }



            function togglePasswordType() {

              var inputPassword = document.getElementById('inputPassword');

              var icon =document.getElementById('icon_password');



              if (inputPassword.type === 'password') {

                inputPassword.type = 'text';

                icon.innerHTML = '<i class="fa fa-eye-slash" style="font-size:15px"></i>';

              } else {

                inputPassword.type = 'password';

                icon.innerHTML = '<i class="fa fa-eye" style="font-size:15px"></i>';

              }

              inputPassword.focus();

            }

        </script>

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

        <!-- END: JS Assets-->

    </body>

</html>

