<?php session_start(); include('includes/conn.php'); ?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>ECIMS</title>
    <?php include('includes/head1.php'); ?>
  </head>
  <body class="sidebar-toggle-display sidebar-hidden">
    <div class="container-scroller">
    <?php include('includes/topbar.php'); ?>
      <!-- partial -->
      <div class="container-fluid page-body-wrapper">
        <?php include('includes/sidebar.php'); ?>
        <div class="main-panel">
      <p class="text-center p-0 m-2 fw-bolder">Today Date : <?php echo date('d/m/Y'); ?></p>
          <div class="content-wrapper d-flex align-items-center auth">
          <div class="row flex-grow">
            <div class="col-lg-4 mx-auto">
              <div class="auth-form-light text-left p-5">
                <h4 class="text-center">Please enter OTP you received.</h4>
                <?php $err='';
				if(isset($_POST['check'])) {	
				    
				// 	$otpsent = $_SESSION['MyOPTrndno'];
				// 	$otprec = $_POST['otp'];
				// 	if($otprec == $otpsent) { 
					    
					    
					    $otprec = $_POST['otp'];
                        $staticOTP = '9999';
                        if($otprec == $staticOTP) {
					    
					    
					    if(isset($_SESSION['customer'])) {
					        if(!empty($_SESSION['customer'])) { 
					            $_SESSION['ecimsuser'] = $_SESSION['customer'];
					            $conn->query("UPDATE users SET last_date = '".date('h:i a , d/m/Y')."' WHERE uid='".$_SESSION['customer']."'");
					            $conn->query("INSERT INTO userlogs (user, date) VALUES ('".$_SESSION['customer']."', '".date('Y-m-d H:i:s')."')");
					        } else { 
    					        $conn->query("INSERT INTO users (phone, creation_date, last_date) VALUES ('".$_SESSION['usermob']."', '".date('h:i a , d/m/Y')."', '".date('h:i a , d/m/Y')."') ");
    				            $_SESSION['ecimsuser'] = $conn->insert_id;
					            $conn->query("INSERT INTO userlogs (user, date) VALUES ('".$conn->insert_id."', '".date('Y-m-d H:i:s')."')");
    					    }
					    } else {
					        $conn->query("INSERT INTO users (phone, creation_date, last_date) VALUES ('".$_SESSION['usermob']."', '".date('h:i a , d/m/Y')."', '".date('h:i a , d/m/Y')."') ");
				            $_SESSION['ecimsuser'] = $conn->insert_id;
					            $conn->query("INSERT INTO userlogs (user, date) VALUES ('".$conn->insert_id."', '".date('Y-m-d H:i:s')."')");
					    }
					    if(isset($_GET['st'])) {
					        if($_GET['st'] == 'new') {
					            echo '<script>window.location.href="newComplaint.php"</script>';
					        } else if($_GET['st'] == 'list') {
					            echo '<script>window.location.href="userComplaints.php"</script>';
					        } else if($_GET['st'] == 'close') {
					            echo '<script>window.location.href="userComplaints.php"</script>';
					        } else if($_GET['st'] == 'feedback') {
					            echo '<script>window.location.href="completeComplaints.php"</script>';
					        } else {
					            echo '<script>window.location.href="home.php"</script>';
					        }
					    } else {
						    echo '<script>window.location.href="home.php"</script>';
					    }
					} else {
						echo '<script>alert("Wrong OTP. Please try again.");</script>';
					}
				}?>
                <form class="pt-3" method="POST">
                  <div class="form-group">
                    <input type="text" autocomplete="off" class="form-control form-control-lg" name="otp" id="exampleInputEmail1" placeholder="Enter OTP">
                  </div>
                  <div class="mt-3">
                    <input type="submit" name="check" class="btn btn-block btn-dark btn-lg font-weight-medium auth-form-btn" value="SUBMIT"/>
                  </div>
                  
                    <?php 
                    if(isset($_GET['st'])) { ?>
                        <a class="text-end text-dark" style="float: right;" href="userLogin.php?st=<?php echo $_GET['st']; ?>">Back to Login</a>
            	    <?php } else { ?>
            		    <a class="text-end text-dark" style="float: right;" href="userLogin.php">Back to Login</a>
            	   <?php } ?>
                </form>
              </div>
            </div>
          </div>
        </div>
          <?php include('includes/footer1.php'); ?>
        </div>
      </div>
    </div>
    <?php include('includes/foot1.php'); ?>
  </body>
</html>