<?php
include_once("../include/main.inc.php");
$ip = $_SERVER['REMOTE_ADDR'];
$title = "Admin Login Panel";
@extract($_REQUEST);
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();
}

//admin_header();
if ($_GET['id1'] == "Logout") {
  session_destroy();
  header("Location:$PHP_SELF");
}
if (isset($_SESSION['MyCpanel'])) {
  header("Location:welcome.php");
} else {
  if ($_POST['id1'] == "login") {
    @extract($_POST);

    $sql1 = "select slno, companyName, last_login, user_type, user_id, country from admin_details where user_id='" . $login_id . "' and pwd='" . $password . "' and user_type='" . $user_type . "'";
    $db = mysqli_query($GLOBALS['dbconn'], $sql1);
    $num = mysqli_num_rows($db);
    if ($num > 0) {
      $res = mysqli_fetch_object($db);
      //print_r($res);
      $_SESSION['MyCpanel'] = $res->last_login;
      $_SESSION['MyAdminUserType'] = $res->user_type;
      $_SESSION['MyAdminUserID'] = $res->user_id;
      $_SESSION['MyAdminCountry'] = $res->country;
      $_SESSION['MyAdminUserSLNO'] = $res->slno;
      $_SESSION['companyName'] = $res->companyName;

      header("location:welcome.php");
      exit;
    } else {
      $_SESSION['session_message'] = "Invalid Username/Password!! ";
      header("Location:index.php");
      exit();
    }
  }
  ?>

  <html>
    <head>
      <link rel="stylesheet" type="text/css" href="login-style.css">
      <link href="css/font-awesome.min.css" rel="stylesheet" type="text/css" />
      <title><?= $title ?></title>	 
      <link href="css/bootstrap.css" rel="stylesheet" type="text/css" />	 
    </head>
    <body>
      <div class="limiter"  style="background-image: url('images/bg-01.jpg');">
        <div class="container-login100">
        <!-- 	<a href="https://www.webpulseindia.com/" target="_blank" class="logo-top"><img src="images/webpulse-logo.png"></a> -->
          <div class="wrap-login100 p-l-55 p-r-55 p-b-54 text-center">
            <div class="clogo">
              <img src="<?= SITE_ADMIN_URL; ?>/images/webpulse-logo.png">
            </div>
            <?php
            $admin = mysqli_query($GLOBALS['dbconn'], "select * from admin_details");
            $result_array = mysqli_fetch_array($admin);
            ?>
            <form class="login100-form validate-form" method="POST" action=''>
                <!-- <span class="login100-form-title p-b-49">
              <?php echo $result_array['companyName']; ?> Admin Panel
                </span> -->
              <span class="red">
                <?php
                if ($_SESSION['session_message'] != '') {
                  echo $_SESSION['session_message'];
                  $_SESSION['session_message'] = '';
                }
                ?>
              </span>

              <div class="wrap-input100 validate-input m-b-23" data-validate="Username is reauired">
                  <!-- <span class="label-input100">Username</span> -->
                <input class="input100" type="text" name="login_id" placeholder="Type your username" autocomplete="off">
                <i class="fa fa-user icon-fa"></i>
              </div>

              <div class="wrap-input100 validate-input" data-validate="Password is required">
                  <!-- <span class="label-input100">Password</span> -->
                <input class="input100" type="password" name="password" placeholder="Type your password" autocomplete="off">
                <input class="input100" type="hidden" name="user_type" value="admin">
                <i class="fa fa-lock icon-fa"></i>
              </div>

              <div class="text-right p-t-8 p-b-31">

              </div>

              <div class="container-login100-form-btn">
                <div class="wrap-login100-form-btn">
                  <div class="login100-form-bgbtn"></div>
                  <button class="login100-form-btn" type="submit" name="id1" value="login">
                    Login
                  </button>
                </div>
              </div>







            </form>
          </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>
        </div>

      </div>
      <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script type="text/javascript" src="js/bootstrap.min.js"></script>	
      <script language="javascript" src="js/admin.js"></script>

    </body>

  </html>

<?php } ?>
