<?php
session_start(); // Start the session

include_once("../include/main.inc.php");

$ip = $_SERVER['REMOTE_ADDR'];
$title = "Admin Login Panel";

if ($_REQUEST['action'] == "remind_password") {
  $res = getResult("admin_details", " where 1");
  $To = $res['email'];
  $from = SITE_EMAIL;
  $fromName = getAdminname();
  $message = 'Dear ' . $res['name'] . ',<br/><br/>Your username is : ' . $res['user_id'] . '<br/>Your password is : ' . $res['pwd'] . '<br /><br />Regards<br /><br />' . $_SESSION['companyName'] . ' Customer Support Team<br />' . SITE_EMAIL;
  send_email($fromName, $from, $To, $subject, $message);
  $_SESSION['session_message'] = "An intimation mail has been sent to your email id about username and password.";
  header("location:index.php");
  exit();
}

if ($_GET['id1'] == "Logout") {
  session_destroy();
  echo "<script>window.location.href='".admin_url."index.php';</script>";
  exit();
}

if (isset($_SESSION['MyCpanel'])) {
  header("Location:welcome.php");
  exit();
} else {
  if ($_POST['id1'] == "login") {
    @extract($_POST);

    $sql1 = "select slno, last_login, name, user_type, user_id, country from admin_details where user_id='" . $login_id . "' and pwd='" . $password . "' and status='Y'";
    $db = mysqli_query($GLOBALS['dbconn'], $sql1);
    $num = mysqli_num_rows($db);

    if ($num > 0) {
      $res = mysqli_fetch_object($db);
      $admin_detail = getAdminDetails();
      ob_start();
      $_SESSION['MyCpanel'] = $res->last_login;
      $_SESSION['MyAdminUserType'] = $res->user_type;
      $_SESSION['MyAdminUserName'] = $res->name;
      $_SESSION['MyAdminUserID'] = $res->user_id;
      $_SESSION['MyAdminCountry'] = $res->country;
      $_SESSION['MyAdminUserSLNO'] = $res->slno;
      $_SESSION['companyName'] = $admin_detail['companyName'];
      echo "<script>window.location.href='".admin_url."welcome.php';</script>";
      exit();
    } else {
      $_SESSION['session_message'] = "Invalid Username/Password!! ";
      header("Location:index.php");
      exit();
    }
  }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title> Admin Login Panel</title>
  <!-- plugins:css -->
  <link rel="stylesheet" href="<?=admin_url?>vendors/iconfonts/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="<?=admin_url?>vendors/css/vendor.bundle.base.css">
  <link rel="stylesheet" href="<?=admin_url?>vendors/css/vendor.bundle.addons.css">
  <!-- endinject -->
  <!-- plugin css for this page -->
  <!-- End plugin css for this page -->
  <!-- inject:css -->
  <link rel="stylesheet" href="<?=admin_url?>css/style.css">
  <!-- endinject -->
  <link rel="icon" href="<?=theme_url?>images/favicon.png">
  <style>
    footer {
    position: absolute;
    bottom: 0px;
    width: 100%;
    background: transparent;
    padding: 11px 0px;
    font-weight: 400;
    z-index: 99999;
    color: #000;
}
  </style>
</head>

<body>
  <div class="container-scroller">
    <div class="container-fluid page-body-wrapper full-page-wrapper">
      <div class="content-wrapper d-flex align-items-center auth">
        <div class="row w-100">
          <div class="col-lg-4 mx-auto">
            <div class="auth-form-light text-left p-5">
              <div class="brand-logo">
                <img src="<?=theme_url;?>images/logo.png" alt="logo">
              </div>
              <!--<h4>Hello! let's get started</h4>-->
              <h6 class="font-weight-light">Sign in to continue.</h6>
              <span style="color:red">
                <?php
                if (isset($_SESSION['session_message']) && $_SESSION['session_message'] != '') {
                  echo $_SESSION['session_message'];
                  $_SESSION['session_message'] = '';
                }
                ?>
              </span>
              <form class="pt-3" method="POST" action=''>
                <div class="form-group">
                  <input type="text" class="form-control form-control-lg" name="login_id" placeholder="Username" required>
                </div>
                <div class="form-group">
                  <input type="password" class="form-control form-control-lg" name="password" placeholder="Password" required>
                </div>
                <div class="mt-3">
                  <button class="btn btn-block btn-primary btn-lg font-weight-medium auth-form-btn"  type="submit" name="id1" value="login">Login</button>
                </div>
              </form>
            </div>
          </div>
        </div>
      </div>
      <!-- content-wrapper ends -->
    </div>
    <!-- page-body-wrapper ends -->
  </div>
  <footer>
    <div class="col-lg-12 col-md-12 text-center">Powered by Webpulse - <a href="https://www.webpulseindia.com/" target="_blank" title="Web Designing" style="display:inline">Web Designing</a>, <a href="https://www.webpulseindia.com/digital-marketing" target="_blank" title="Digital Marketing" style="display:inline">Digital Marketing</a> &amp; <a href="https://www.webpulseindia.com/branding" target="_blank" title="Branding Company" style="display:inline">Branding Company </a>
    </div>
  </footer>
  <!-- container-scroller -->
  <!-- plugins:js -->
  <script src="<?=admin_url?>vendors/js/vendor.bundle.base.js"></script>
  <script src="<?=admin_url?>vendors/js/vendor.bundle.addons.js"></script>
  <!-- endinject -->
</body>
</html>
