<?php
session_start();
require_once('includes/init.php');

$errors = array();

$_SESSION['token'] = null;
setcookie('token', '', time() - 3600);


$did = compactify($conn, $_GET['did']);
$query = "SELECT * FROM users WHERE did ='$did' ";
        $result = mysqli_query($conn, $query);
        if (mysqli_num_rows($result) == 1) {
            start_user_session(mysqli_fetch_assoc($result)['token']);
            header('location: index.php?' . http_build_query($_GET));

        }


if(isset($_POST['log_user']))
{
    $login_mobile = $_POST['mobile'];
    $login_password = $_POST['password'];
    $did = compactify($conn, $_POST['did']);
    
    # VALIDATE

    if (empty($did)) {
        array_push($errors, "Unsupported device");
    }
    
    if (empty($login_mobile)) {
        array_push($errors, "Mobile is required");
    }
    
    if (empty($login_password)) {
        array_push($errors, "Password is required");
    }
    
    $mobile = compactify($conn, $login_mobile);
    $password = md5($login_password);
    
    if (count($errors) == 0) {
        $sql = "SELECT * FROM users WHERE mobile='$mobile'";
        $result = mysqli_query($conn, $sql);
        if (!mysqli_num_rows($result) == 1) {
            array_push($errors, "Mobile not found");
        }
    }
    
    /*if (count($errors) == 0) {
        $sql = "SELECT * FROM users WHERE mobile='$mobile' AND did = '$did'";
        $result = mysqli_query($conn, $sql);
        if (!mysqli_num_rows($result) == 1) {
            array_push($errors, "Use registration device");
        }
    }*/
    
    if (count($errors) == 0) {
        $query = "SELECT * FROM users WHERE mobile='$mobile' AND password='$password'";
        $result = mysqli_query($conn, $query);
        if (mysqli_num_rows($result) == 1) {
            start_user_session(mysqli_fetch_assoc($result)['token']);
            header('location: index.php?' . http_build_query($_GET));

        } else {
            array_push($errors, "Incorrect password");
        }
    }
    
    $errors = array_slice($errors, 0, 2);
    
}


$string = file_get_contents("../This_is_Admin_/app-data.json");
$json_a = json_decode($string, true);


mysqli_close($conn);

?>
<!DOCTYPE html>
<html>
<head>
    <title>Log In</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=false">
    <link rel="stylesheet" href="css/style.css">
    <link defer rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
 <link href="https://fonts.googleapis.com/css?family=Nunito:600,700,900" rel="stylesheet">
 <script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
    <style>
        <?php include 'css/custom-style.php' ?>
        #body {
  font-family: 'Nunito';
background-color:  #5d8fc9;
}
#login-card{
    width:350px;
    border-radius: 25px;
    margin:150px auto;
  
}

#email{
    border-radius:30px;
    background-color: #ebf0fc;
    border-color: #ebf0fc;
    color: #9da3b0;
    width: 60%;
}

#button{
    border-radius:30px;
    width: 60%;
    color:white;

}

#btn{
   position: absolute; 
   bottom: -35px; 
   padding: 5px;
   margin: 0px 55px;
   align-items: center;
   border-radius: 5px;
}
#container{
    margin-top:25px;
}

.btn-circle.btn-sm { 
            width: 40px; 
            height: 40px; 
            padding: 2px 0px; 
            border-radius: 25px; 
            font-size: 14px; 
            text-align: center;
            
            margin: 8px;
        }
.logoicon{
    position: absolute; 
   top: -50px; 
   margin: 0;
   align-items: center;
   display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}    
.logoicon img{
   margin: 0;
   align-items: center;
   border-radius: 50%;
   border: 3px solid white;
   display: flex;
    justify-content: center;
    align-items: center;
}


.bg-main {background: linear-gradient(<?= $json_a['color_primary']  ?>, <?= $json_a['color_secondary']  ?>) !important}body.bg-main {background: linear-gradient(<?= $json_a['color_primary']  ?>, <?= $json_a['color_secondary']  ?>) !important}main.bg-main {background: linear-gradient(<?= $json_a['color_primary']  ?>, <?= $json_a['color_secondary']  ?>) !important}section.bg-main {background: linear-gradient(<?= $json_a['color_primary']  ?>, <?= $json_a['color_secondary']  ?>) !important}div.bg-main {background: linear-gradient(<?= $json_a['color_primary']  ?>, <?= $json_a['color_secondary']  ?>) !important}button.bg-main {background: linear-gradient(<?= $json_a['color_primary']  ?>, <?= $json_a['color_secondary']  ?>) !important}a.bg-main {background: linear-gradient(<?= $json_a['color_primary']  ?>, <?= $json_a['color_secondary']  ?>) !important}.border-pr {border-top: 3.5px solid <?= $json_a['color_primary']  ?> !important}.color-pr {background: <?= $json_a['color_primary']  ?> !important}.text-main {color: <?= $json_a['color_primary']  ?> !important}
    

    </style>

</head>




<!--<?php if($json_a['app_theme']=='Simple') {?>-->

<!--<!DOCTYPE html>-->
<!--<html>-->
<!--<head>-->
<!--<title>Login</title>-->
<!-- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=false">-->
<!--    <link rel="stylesheet" href="css/style.css">-->
<!--    <link defer rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css">-->
<!--    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">-->
<!--  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>-->
<!--  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>-->
<!--  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">-->
<!--  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>-->
<!-- <link href="https://fonts.googleapis.com/css?family=Nunito:600,700,900" rel="stylesheet">-->
<!-- <link rel="stylesheet" href="assets/css/style.elegantpro.css">-->
<!--    <style>-->
<!--		<?php include 'css/login-style.php' ?>-->
<!--		#body {-->
<!--  font-family: 'Nunito';-->
<!--background-color:  #5d8fc9;-->
<!--}-->
<!--#login-card{-->
<!--    width:350px;-->
<!--    border-radius: 25px;-->
<!--    margin:150px auto;-->
  
<!--}-->

<!--#email{-->
<!--    border-radius:50px;-->
<!--    background-color: #ebf0fc;-->
<!--    border-color: #ebf0fc;-->
<!--    color: #9da3b0;-->
<!--    width: 70%;-->
<!--}-->
<!--.rainbow-divider {-->
<!--	outline: none;-->
<!--	border: none;-->
<!--    height: 4px;-->
<!--    background-image:-->
<!--    linear-gradient(-->
<!--      to right, -->
<!--      #E15100 20%,-->
<!--      #FDCD78 20%,-->
<!--      #FDCD78 40%,-->
<!--      #4CAF50 40%,-->
<!--      #4CAF50 60%,-->
<!--      #D99DBF 60%,-->
<!--      #D99DBF 80%,-->
<!--      #679DE2 80%-->
<!--    );-->
<!--}-->

<!--#button{-->
<!--    border-radius:30px;-->
<!--    width: 60%;-->
<!--    color:white;-->

<!--}-->
<!--.bg-signup {-->
<!--    background: #623AA2;-->
<!--}-->
<!--#btn{-->
<!--   position: absolute; -->
<!--   bottom: -35px; -->
<!--   padding: 5px;-->
<!--   margin: 0px 55px;-->
<!--   align-items: center;-->
<!--   border-radius: 5px"-->
<!--}-->
<!--#container{-->
<!--    margin-top:25px;-->
<!--}-->

<!--.btn-circle.btn-sm { -->
<!--            width: 40px; -->
<!--            height: 40px; -->
<!--            padding: 2px 0px; -->
<!--            border-radius: 25px; -->
<!--            font-size: 14px; -->
<!--            text-align: center;-->
            
<!--            margin: 8px;-->
<!--        }-->
<!--.logoicon{-->
<!--    position: absolute; -->
<!--   top: -50px; -->
<!--   margin: 0;-->
<!--   align-items: center;-->
<!--   display: flex;-->
<!--    justify-content: center;-->
<!--    align-items: center;-->
<!--    width: 100%;-->
<!--}  -->
<!--.mmm{-->
<!--     position: absolute; -->
<!--   bottom: -20px; -->
<!--   margin: 0;-->
<!--   align-items: center;-->

<!--    justify-content: center;-->
<!--    align-items: center;-->
<!--    width: 100%;-->
<!--}-->
<!--#button2{-->
<!--    border-radius:30px;-->
<!--    width: 60%;-->
<!--    color:white;-->

<!--}-->
<!--.logoicon img{-->
<!--   margin: 0;-->
<!--   align-items: center;-->
<!--   border-radius: 50%;-->
<!--   border: 3px solid white;-->
<!--   display: flex;-->
<!--    justify-content: center;-->
<!--    align-items: center;-->
<!--}-->
<!--.topbar { -->
<!--      background: <?= $bg_top ?> !important;-->
<!--      border-radius:0px 0px 60px 60px;-->
<!--      padding: 10px;-->
      
<!--}-->

<!--.bg_top{-->
<!--    background: <?= $bg_top ?> !important;-->
<!--}-->


<!--	</style>-->
<!--</head>-->
<!--<body class="bg-white">  -->
<!--<section class="topbar">-->
<!--   <br><br><br><br><br><br>-->
<!--</section>-->
<!--<div class="notice-bg">-->
<!--<div class="notice-block">-->
<!--  <div class="logoicon">-->
<!--                   <img src="https://appslabbdinfo.com/image/avatar.png" height="100px" width="100px"/>-->
<!--               </div>-->

<!--  <br><br><br><div class="box">-->
<!--     <center>-->
<!--  <form autocomplete="off" method="post" action="login.php">-->
<!--      <?php foreach ($errors as $error) : ?>-->
<!--  		  <p class="kalpurush gray"><?php echo $error ?></p>-->
<!--       <?php endforeach ?>-->
<!--       <input type="hidden" id="did" name="did">-->
<!--            <script type="text/javascript">-->
<!--                var did_app = Android.getDeviceId();-->
<!--				document.getElementById("did").value = did_app;-->
<!--            </script>-->
<!--              <?php if ($json_a['user_account_type']==0) {?>-->
<!--    <div class="form-group">-->
<!--      <input type="number" class="form-control" id="email" placeholder="Enter Number" value="<?= $_POST['mobile'] ?? ''?>" name="mobile">-->
<!--    </div>-->
<!--    <?php }else{  ?>-->
<!--    <div class="form-group">-->
<!--      <input type="number" class="form-control" id="email" placeholder="Enter Number" value="<?= $_POST['mobile'] ?? ''?>" name="mobile">-->
<!--    </div>-->
<!--    <?php } ?>-->
<!--    <div class="form-group">-->
<!--      <input type="password" class="form-control" id="email" placeholder="Enter password" name="password">-->
<!--    </div>-->
<!--    <button  name="log_user" type="submit" id="button" class="btn bg_top deep-purple btn-block">LOGIN</button>-->
<!--  </form>-->
<!--                <hr class="rainbow-divider" style="width: 40%; margin: 1em; margin-bottom: 10px;">-->
               
<!--                <button onclick="Android.openWebActivity('Sign Up', 'sign-up')" id="button2" class="btn bg-signup  deep-purple btn-block">Sign Up</button>-->
<!--             </div><br>-->
<!--                 </div>-->
          
  
   
<!--       </section>  -->
<!--             <br>-->
<!--  </center></div>-->
<!-- </div>-->
<!--<div>-->
  
 

   
	
<!--</body>-->

<!--</html>-->


<!--<?php } ?>-->

<!--<?php if($json_a['app_theme']==1) {?>-->
<!--<!DOCTYPE html>-->
<!--<html>-->

<!--<head>-->
<!--    <title>Login</title>-->
<!--    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" type="text/css">-->
<!--    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">-->
<!--    <link rel="stylesheet" href="css/style.classic.css">-->
  
<!--</head>-->

<!--<body class="bg-main">-->

<!--    <div class="main">-->
<!--         <form autocomplete="off" method="post" action="login.php">-->
<!--               <h2>Sign In</h2>-->
<!--     <?php foreach ($errors as $error) : ?>-->
<!--  		  <p class="kalpurush gray"><?php echo $error ?></p>-->
<!--       <?php endforeach ?>-->
<!--       <input type="hidden" id="did" name="did">-->
<!--            <script type="text/javascript">-->
<!--                var did_app = Android.getDeviceId();-->
<!--				document.getElementById("did").value = did_app;-->
<!--            </script>-->

<!--               <?php if ($json_a['user_account_type']==0) {?>-->
<!--            <div class="input-container">-->
<!--                <i>email</i>-->
<!--                <input class="input-field no-font" type="email" value=""-->
<!--                    placeholder="Email" name="mobile">-->
<!--            </div>-->
<!--            <?php }else{  ?>-->
<!--             <div class="input-container">-->
<!--                <i>phone_android</i>-->
<!--                <input class="input-field no-font" type="number" value=""-->
<!--                    placeholder="Mobile" name="mobile">-->
<!--            </div>-->
<!--            <?php } ?>-->
<!--            <div class="input-container">-->
<!--                <i>security</i>-->
<!--                <input class="input-field masque" type="password" placeholder="Enter password" name="password">-->
<!--            </div>-->

<!--            <button name="log_user" type="submit" class="exodus">Sign In</button>-->
<!--        </form>-->
<!--        <br />-->

<!--        <button onclick="Android.openWebActivity('Sign Up', 'sign-up')" class="exodus">Sign Up</button>-->

<!--    </div>-->

 
<!--</body>-->

<!--</html>-->
<!--<?php } ?>-->


<!--</html>-->


<!--<?php if($json_a['app_theme']=='Classic') {?>-->


<!--<style>-->
    
<!--    .from-imp {-->
<!--        padding:14px;-->
<!--        border-radius:5px;-->
<!--        width:90%;-->
<!--        margin:20px;-->
<!--        background: #f1f1f1;-->
<!--    }-->
        
<!--    .form-imp2 { -->
<!--      width: 100%;-->
<!--      height: $input-height;-->
<!--      padding: $input-padding-y $input-padding-x;-->
<!--      font-size: $font-size-base;-->
<!--      line-height: $input-line-height;-->
<!--    }-->

<!--.login-btn {-->
<!--	background-color: red;-->
<!--}-->

<!--.register-btn {-->
<!--	background-color: #16C2F2;-->
<!--}-->

<!--.bg-sigin{-->
<!--    border-radius: 5px;-->
<!--    width: 120px;-->
<!--    height: 45px;-->
<!--    margin-bottom: 15px;-->
<!--    color: white;-->
<!--    background: #fe1a19;-->
<!--}-->

<!--.bg-siginup{-->
<!--    border-radius: 5px;-->
<!--    border-radius: 5px;-->
<!--    width: 300px;-->
<!--    height: 48px;-->
<!--    color: white;-->
<!--    background: #2fc8f2;-->
<!--}-->

<!-- </style>-->
<!--</head>-->
<!--<body class="bg-main" style="margin-top:15px;"> -->
<!--<div>-->

<!--  <div>-->
<!--     <center>-->
         
<!--   <form autocomplete="off" method="POST" action="login.php">-->
<!--       <?php if ($json_a['user_account_type']==0) {?>-->
<!--                <div class="from-imp">-->
<!--                    <input name="mobile" class="form-imp2" style="color:black; font-size:15px; background: #f1f1f1;" placeholder="Mobile" type="number" value="">-->
<!--                </div>-->
<!--                <?php }else{  ?>-->
<!--                <div class="from-imp">-->
<!--                    <input name="mobile" class="form-imp2" style="color:black; font-size:15px; background: #f1f1f1;" placeholder="Mobile" type="number" value="">-->
<!--                </div>-->
<!--                <?php } ?>-->
<!--                <div class="from-imp">-->
<!--                    <input name="password" class="form-imp2" style="color:black; font-size:15px; background: #f1f1f1;" placeholder="Password" type="password">-->
<!--                </div>-->
<!--                      <?php foreach ($errors as $error) : ?>-->
<!--                      <p class="alert alert-danger"><?php echo $error ?></p>-->
<!--                   <?php endforeach ?>-->
<!--                   <input type="hidden" id="did" name="did">-->
<!--                        <script type="text/javascript">-->
<!--                            var did_app = Android.getDeviceId();-->
<!--                            document.getElementById("did").value = did_app;-->
<!--                    </script>-->
<!--                <button name="log_user" type="submit" style="width: 92%; margin-bottom:15px; height: 45px;" class="btn bg-sigin deep-purple btn-block">Sign In</button>-->
<!--                <button class="btn bg-siginup deep-purple btn-block" style="width: 92%; margin-bottom:15px; height: 45px;" onclick="Android.openWebActivity('Sign Up', 'sign-up')">Sign Up</button>-->
<!--            </form>-->
            
<!--</section>-->
  
<!--       </section>   -->
<!--</body>-->
<!--<?php } ?>-->







<!DOCTYPE html>
<html>
<head>
    <title>Log In</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
        <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet" type="text/css">
		<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css" >
		<link rel="stylesheet" href="css/bg.css" >
    <style>
		


i, .material-icons {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  font-size: 24px;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-block;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-smoothing: antialiased;
  
}
.icons:active {
	transform: scale(0.8);
}
.icons {
    margin:6px;
    color: <?php echo($app_data['color_primary']);?>  !important;
    font-size: 22px;
    background: lavender ;
    border-radius: 50% ;
    padding: 6px;
    transition: all 0.1s ease-in-out;
}		#body {
  font-family: 'Nunito';
background-color:  #5d8fc9;
}
#login-card{
    width:350px;
    border-radius: 25px;
    margin:150px auto;
  
}

#email{
    border-radius:5px;
    background-color: #ffffff;
    border-color: #ebf0fc;
    color: #9da3b0;
}

div1:hover{
    border-color:red;
}
.rainbow-divider {
	outline: none;
	border: none;
    height: 3px;
    background:#dcdcdc;
}

#button{
    border-radius:5px;
    width: 120px;
    height:48px;
    margin-right:12px;
    margin-bottom:18px;
    float: right;
    color:white;
    background:#5e72e3;

}
.bg-signup {
    background: #C04848;
}
#btn{
   bottom: -35px; 
   padding: 5px;
   margin: 0px 55px;
   align-items: center;
   border-radius: 5px"
}
#container{
    margin-top:25px;
}

.btn-circle.btn-sm { 
            width: 40px; 
            height: 40px; 
            padding: 2px 0px; 
            border-radius: 25px; 
            font-size: 14px; 
            text-align: center;
            
            margin: 8px;
        }
.logoicon{ 
   top: -50px; 
   margin: 0;
   align-items: center;
   display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
}  
.mmm{
   bottom: -20px; 
   margin: 0;
   align-items: center;
    justify-content: center;
    align-items: center;
    width: 100%;
}
#button2{
    border-radius:5px;
    border-radius:5px;
    width: 300px;
    height:48px;
    color:white;
    background: #5e72e3;

}
.logoicon img{
   margin: 0;
   align-items: center;
   border-radius: 50%;
   border: 3px solid white;
   display: flex;
    justify-content: center;
    align-items: center;
}
.div1 {
  width:86%;
  display: -ms-flexbox;
  display: flex;
  margin: 25px;
  padding:12px;
  background: white;
  border: 2px solid #d1cdcd;
  border-radius:3px;
  
}
.div1:hover{
  --c:  <?php echo($app_data['color_primary']);?> !important;
  border-color: <?php echo($app_data['color_primary']);?>  !important;
  border: 2px solid ;
}

.input-fields {
  width: 100%;
  padding: 15px;
  outline: none;
  border: none;
}

.no-fonts {
	font-family: 'Algerian';
}
.form-my { 
  width: 100%;
  height: $input-height;
  padding: $input-padding-y $input-padding-x;
  font-size: $font-size-base;
  line-height: $input-line-height;
  color: #000000;
  background-clip: padding-box;
  border: $input-border-width solid $input-border-color;
}
.ico {
    margin-left:5px;
    margin-right:10px;
    color: var(--c);
    font-size: 35px;
    border-radius: 50% ;
    transition: all 0.1s ease-in-out;
}
i, .material-ico {
  font-family: 'Material Icons';
  font-weight: normal;
  font-style: normal;
  text-transform: none;
  display: inline-block;
  letter-spacing: normal;
  white-space: nowrap;
  word-wrap: normal;
  direction: ltr;
  -webkit-font-smoothing: antialiased;
  font-size: 24px;
}



	</style>
</head>
<body class="bg-main" style="margin-top:15px;"> 
<div style="margin-right:15px; margin-left:15px; background:white ; color:black; border-radius: 3px; border: 1px solid #e8e8e8 ; : relative;">
     <center><div style="margin-top:18px; ">
                   <img src="img/profile.png" height="100px" width="100px"/>
               </div></center>

  <div>
     <center>

      
       <form autocomplete="off" method="post" action="login.php">
      <?php foreach ($errors as $error) : ?>
  		  <p class="kalpurush gray"><?php echo $error ?></p>
       <?php endforeach ?>
      
             <input type="hidden" id="did" name="did">
            <script type="text/javascript">
                var did_app = Android.getDeviceId();
				document.getElementById("did").value = did_app;
            </script>
            <?php if ($json_a['user_account_type']==0) {?>
    <div class="div1" style="margin-bottom:20px;">
	  <i class="material-ico ico">email</i>
      <input type="email" class="form-my" style="color:black; font-size:15px;" placeholder="Email" value="" name="mobile">
    </div>
    <?php }else{  ?>
      <div class="div1" style="margin-bottom:20px;">
	  <i class="material-ico ico">phone_android</i>
      <input type="number" class="form-my" style="color:black; font-size:15px;" placeholder="Mobile" value="" name="mobile">
    </div>
    <?php } ?>
    <div class="div1">
	  <i class="material-ico ico">security</i>
      <input type="password" class="form-my" style="color:black; font-size:15px;" id="email" placeholder="Enter password" name="password">
    </div>
    
    <button  name="log_user" type="submit" id="button">Login</button>
  </form>
  <br><br>
                <hr class="rainbow-divider" style="width: 91%; margin: 1em; margin-bottom: 24px;">
                <div class="myd">
                <button onclick="Android.openWebActivity('Sign Up', 'sign-up')" id="button2" class="btn bg-signup mm" style="width: 92%; margin-bottom:20px; height: 50px;">Create New Account</button>
             </div>
             
  </center></div>
 </div>
    	  
	
</body>
</html>






