<?php
    session_start();
    ob_start();
    include "../db.php";

    

?>
<!DOCTYPE html>
<html lang="en">

<head>
    <?php include "include/meta.php"; ?>
    <?php include "include/css.php"; ?>
    <link href="css/all.min.css" rel="stylesheet" type="text/css">
    <link href="css/alltable.css" rel="stylesheet">
    <style>
    .items-mobile {
        margin: 30px 0 0;
        border: 2px solid #adadad;
        padding: 10px 0;
        height: 150px;
        background-color: #fff;
    }

    .items-mobile .project-name p {
        font-weight: bold;
        font-size: 12px;
        margin: 12px 0;
    }

    .icon-wrapper i {
        font-size: 82px;
    }

    .items-mobile:hover {
        box-shadow: 0 0.25rem 0.5rem #6e8ca5;
    }
    </style>

    <style>
    body {
        font-family: "Lato", sans-serif;
    }

    .sidenav {
        height: 100%;
        width: 0;
        position: fixed;
        z-index: 1;
        top: 0;
        left: 0;
        background-color: #111;
        overflow-x: hidden;
        transition: 0.5s;
        padding-top: 60px;
    }

    .sidenav a {
        padding: 8px 8px 8px 32px;
        text-decoration: none;
        font-size: 25px;
        color: #818181;
        display: block;
        transition: 0.3s;
    }

    .sidenav a:hover {
        color: #f1f1f1;
    }

    .sidenav .closebtn {
        position: absolute;
        top: 0;
        right: 25px;
        font-size: 36px;
        margin-left: 50px;
    }

    @media screen and (max-height: 450px) {
        .sidenav {
            padding-top: 15px;
        }

        .sidenav a {
            font-size: 18px;
        }
    }
    </style>
    <style>
    * {
        box-sizing: border-box
    }

    /* Set height of body and the document to 100% */
    body,
    html {
        height: 100%;
        margin: 0;
        font-family: Arial;
    }

    /* Style tab links */
    .tablink {
        background-color: #555;
        color: white;
        border: none;
        outline: none;
        cursor: pointer;
        padding: 14px 16px;
        font-size: 17px;
        width: 100%;
    }

    .tablink:hover {
        background-color: #777;
    }

    /* Style the tab content (and add height:100% for full page content) */
    .tabcontent {
        color: white;
        display: none;
        padding: 100px 20px;
        height: 100%;
    }

    #Home {
        background-color: #D1D0C0;
    }

    #News {
        background-color: #D1D0C0;
    }
    </style>
    <style>
    /* sign in FORM */
    #logreg-forms {
        width: 412px;
        margin: 10vh auto;
        background-color: #f3f3f3;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.24);
        transition: all 0.3s cubic-bezier(.25, .8, .25, 1);
    }

    #logreg-forms form {
        width: 100%;
        max-width: 410px;
        padding: 15px;
        margin: auto;
    }

    #logreg-forms .form-control {
        position: relative;
        box-sizing: border-box;
        height: auto;
        padding: 10px;
        font-size: 16px;
    }

    #logreg-forms .form-control:focus {
        z-index: 2;
    }

    #logreg-forms .form-signin input[type="email"] {
        margin-bottom: -1px;
        border-bottom-right-radius: 0;
        border-bottom-left-radius: 0;
    }

    #logreg-forms .form-signin input[type="password"] {
        border-top-left-radius: 0;
        border-top-right-radius: 0;
    }

    #logreg-forms .social-login {
        width: 390px;
        margin: 0 auto;
        margin-bottom: 14px;
    }

    #logreg-forms .social-btn {
        font-weight: 100;
        color: white;
        width: 190px;
        font-size: 0.9rem;
    }

    #logreg-forms a {
        display: block;
        padding-top: 10px;
        color: lightseagreen;
    }

    #logreg-form .lines {
        width: 200px;
        border: 1px solid red;
    }


    #logreg-forms button[type="submit"] {
        margin-top: 10px;
    }

    #logreg-forms .facebook-btn {
        background-color: #3C589C;
    }

    #logreg-forms .google-btn {
        background-color: #DF4B3B;
    }

    #logreg-forms .form-reset,
    #logreg-forms .form-signup {
        display: none;
    }

    #logreg-forms .form-signup .social-btn {
        width: 210px;
    }

    #logreg-forms .form-signup input {
        margin-bottom: 2px;
    }

    .form-signup .social-login {
        width: 210px !important;
        margin: 0 auto;
    }

    /* Mobile */

    @media screen and (max-width:500px) {
        #logreg-forms {
            width: 300px;
        }

        #logreg-forms .social-login {
            width: 200px;
            margin: 0 auto;
            margin-bottom: 10px;
        }

        #logreg-forms .social-btn {
            font-size: 1.3rem;
            font-weight: 100;
            color: white;
            width: 200px;
            height: 56px;

        }

        #logreg-forms .social-btn:nth-child(1) {
            margin-bottom: 5px;
        }

        #logreg-forms .social-btn span {
            display: none;
        }

        #logreg-forms .facebook-btn:after {
            content: 'Facebook';
        }

        #logreg-forms .google-btn:after {
            content: 'Google+';
        }
    }
    </style>


    <style>
    .content {
        position: absolute;
        top: 300px;
        left: 50%;
        transform: translate(-50%, -50%);
        background: rgba(0, 0, 0, 0.5);
        color: #f1f1f1;
        padding: 20px;
        border-radius: 5px;
        width: 300px;
        height: 400px;
    }

    @media(max-width:500px) {
        .content {
            left: 50%;
            width: 100%;
        }
    }

    .content3 {
        background: #000;
        color: #fff;
        padding: 20px;
    }

    .testing {
        text-align: right;
    }

    @media(max-width:768px) {
        .testing {
            text-align: left;
        }
    }
    </style>

</head>

<body>

    <!--==========================
  Header
  ============================-->
    <?php include "include/header2.php"; ?>

    <!-- #header -->

    <!--==========================
    Intro Section
  ============================-->


    <div class="container ">
        <div class="row  justify-content-center ">

            <div class="col-12 col-sm-8 col-md-8" style="padding-top:30px;">




            </div>
        </div>
    </div>





    <div id="logreg-forms">


        <button class="tablink" onclick="openPage('News', this, 'green')" id="defaultOpen">
            Sign In</button>


        <div id="News" class="tabcontent">
            <form class="form-signin" method="post">


                <input type="text" maxlength="13" name="uphone" id="inputEmail" class="form-control"
                    placeholder="Mobile Number" required="" autofocus="" onkeypress='validate(event)'>
                <input type="password" name="upass" id="inputPassword" class="form-control" placeholder="Password"
                    style="margin-top:10px;" required="">

                <button class="btn btn-success btn-block" type="submit" name="login_button"><i
                        class="fas fa-sign-in-alt"></i> Sign in</button>

                <a href="#" id="forgot_pswd">Forgot password?</a>

                <hr>

            </form>
            <form method="post" class="form-reset">
                <input type="text" id="resetEmail" class="form-control" placeholder="Mobile Number" name="uphone"
                    required="" autofocus="">
                <button class="btn btn-primary btn-block" type="submit" name="reset_pass">Reset Password</button>
                <a href="#" id="cancel_reset"><i class="fas fa-angle-left"></i> Back</a>
            </form>

        </div>


    </div>


</body>

</html>

<script>
function toggleResetPswd(e) {
    e.preventDefault();
    $('#logreg-forms .form-signin').toggle()
    $('#logreg-forms .form-reset').toggle()
}

function toggleSignUp(e) {
    e.preventDefault();
    $('#logreg-forms .form-signin').toggle();
    $('#logreg-forms .form-signup').toggle();
}

function validate(evt) {
    var theEvent = evt || window.event;
    if (theEvent.type === 'paste') {
        key = event.clipboardData.getData('text/plain');
    } else {
        var key = theEvent.keyCode || theEvent.which;
        key = String.fromCharCode(key);
    }
    var regex = /[0-9]|\./;
    if (!regex.test(key)) {
        theEvent.returnValue = false;
        if (theEvent.preventDefault) theEvent.preventDefault();
    }
}
$(() => {
    $('#logreg-forms #forgot_pswd').click(toggleResetPswd);
    $('#logreg-forms #cancel_reset').click(toggleResetPswd);
    $('#logreg-forms #btn-signup').click(toggleSignUp);
    $('#logreg-forms #cancel_signup').click(toggleSignUp);
})
</script>

<script>
function openPage(pageName, elmnt, color) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablink");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].style.backgroundColor = "";
    }
    document.getElementById(pageName).style.display = "block";
    elmnt.style.backgroundColor = color;
}

// Get the element with id="defaultOpen" and click on it
document.getElementById("defaultOpen").click();
</script>


<?php
    


if(isset($_POST['login_button'])) {

    $uphone = mysqli_real_escape_string($con, strip_tags($_POST['uphone']));
    $upass = mysqli_real_escape_string($con, strip_tags($_POST['upass']));

    $l_sql = "SELECT uid, uname, uphone, upass, utype, uref FROM users WHERE uphone = '$uphone'";
    $l_run = mysqli_query($con, $l_sql);
    if ($l_rows = mysqli_fetch_assoc($l_run)) {
     
            $uidDB = $l_rows['uid'];
            $unameDB = $l_rows['uname'];
            $uphoneDB = $l_rows['uphone'];
            $upassDB = $l_rows['upass'];
            $utypeDB = $l_rows['utype'];
            $urefDB = $l_rows['uref'];


          if ($uphone == $uphoneDB) {

              if ($upass == $upassDB) {

                 

                  $_SESSION["uid"] = $uidDB;
                  $_SESSION["utype"] = $utypeDB;
                  $_SESSION["uname"] = $unameDB;
                  $_SESSION["uref"] = $urefDB;

                  if ( $utypeDB == 'master_admin' ) {
                      header('Location: user1/');
                      exit();
                  }
                  elseif ( $utypeDB == 'basic_lvl_admin' ) {
                      header('Location: user2/');
                      exit();
                  }
              }
              else {
                  ?>
<script>
alert("Wrong Password");
</script>
<?php
              }
          }
          else {
              ?>
<script>
alert("No acount Found");
</script>
<?php
          }
    }
}
if(isset($_POST['reset_pass'])) {

    $uphone = mysqli_real_escape_string($con, strip_tags($_POST['uphone']));

    $l_sql = "SELECT uphone, upass FROM users WHERE uphone = '$uphone'";
    $l_run = mysqli_query($con, $l_sql);
    $l_rows = mysqli_fetch_assoc($l_run);

    $uphoneDB = $l_rows['uphone'];
    $upassDB = $l_rows['upass'];

    if ($uphone == $uphoneDB) {

        $api_key = '45899D6EF8D236';
        $contacts = $uphoneDB;
        $from = 'DIGIXB';
        $sms_text = urlencode('Password to Recover your Acount is '.$upassDB.'. Do not share with anyone.');

        //Submit to server

        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL, "http://manage.sambsms.com/app/smsapi/index.php");
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, "key=".$api_key."&campaign=0&routeid=7&type=text&contacts=".$contacts."&senderid=".$from."&msg=".$sms_text);
        $response = curl_exec($ch);
        curl_close($ch);
        echo $response;

        header("Location: index.php");
        exit();
    }
    else {
        ?>
<script>
alert("No acount Found");
</script>
<?php
    }
}
 

ob_end_flush();

?>

<!--==========================
    Footer
  ============================-->
<?php include "include/ft.php"; ?>

<!-- #footer -->




<!-- JavaScript Libraries -->
<?php include "include/js.php"; ?>