<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="description" content="">
        <meta name="author" content="">
        <title>Srima Ticket Book Login </title>
        <!-- Bootstrap Core CSS -->
        <link href="bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
        
        <!-- Custom CSS -->
        <link href="dist/css/sb-admin-2.css" rel="stylesheet">
        <!-- Custom Fonts -->
        <link href="bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
        <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
        <!--[if lt IE 9]>
            <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
            <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
    </head>
    <body>
        <h2 align="center">Srima Ticket Booking</h2>
        <div class="container">
            <br>
            <div class="col-md-4 col-md-offset-4">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <h3 class="panel-title">Sign In</h3>
                    </div>
                    <div class="panel-body">
                        <form method="post">
                            <fieldset>
                                <div class="form-group">
                                    <input class="form-control" placeholder="Mobile No." id="mobile_no" name="mobile_no" type="text" autofocus autocomplete="off">
                                </div>
                                <div class="form-group">
                                    <input class="form-control" placeholder="Enter OTP" id="mob_otp" name="mob_otp" type="password" value="" style="display:none">
                                </div>
                                <div class="success-msg"></div>
                                
                                <!-- Change this to a button or input when using this as a form -->
                                <button type="button" value="Send OTP" name="send_otp" id="send_otp" class="btn btn-lg btn-success btn-block">Send OTP</button>
                                <input type="button" value="Login" name="submit" id="login" class="btn btn-lg btn-success btn-block" style="display:none">
                                <div class="error-msg"></div>
                            </fieldset>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <!-- jQuery -->
        <script src="bower_components/jquery/dist/jquery.min.js"></script>
        <!-- Bootstrap Core JavaScript -->
        <script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
        <script type="text/javascript">
            $("#send_otp").click(function(){
                var mobile_no = $('#mobile_no').val();
                var send_otp = 1;
                var action = 'send_otp';
                $.ajax({
                    type: "POST",
                    url: "loginverify.php",
                    dataType:"json",
                    data: {mobile_no:mobile_no,send_otp:send_otp,action:action},
                    //cache: false,
                    success: function(data){
                        console.log(data);
                        if(data.is_success){
                            $('#mob_otp').show();
                            $('.success-msg').text(data.message);
                            $('.success-msg').show();
                            $('.error-msg').hide();
                            
                            $('#send_otp').hide();
                            $('#login').show();
                        }else{
                            $('.error-msg').text(data.message);
                            $('.error-msg').show();
                            $('.success-msg').hide();
                            $('#mob_otp').hide();
                            
                            $('#send_otp').show();
                            $('#login').hide();
                        }
                    }
                });
            });    
            $("#login").click(function(){
                var mobile_no = $('#mobile_no').val();
                var mob_otp = $('#mob_otp').val();
                var send_otp = 1;
                var login = 1;
                var action = 'verify_otp';
                $.ajax({
                    type: "POST",
                    url: "loginverify.php",
                    dataType:"json",
                    data: {mobile_no:mobile_no,mob_otp:mob_otp,send_otp:send_otp,action:action},
                    //cache: false,
                    success: function(data){
                        console.log(data);
                        if(data.is_success){
                            window.location = "http://192.168.4.9:72/srimaticket/dashboard.php";
                        }else{
                            $('.error-msg').text(data.message);
                            $('.error-msg').show();
                            $('.success-msg').hide();
                            $('#mob_otp').hide();
                            
                            $('#send_otp').show();
                            $('#login').hide();
                        }
                    }
                });
            });
           
        </script>
    </body>
</html>
