<?php
	//if($_SESSION['admin']){session_destroy();} //clear session first

	$conn = mysqli_connect("localhost","dzvisual_admin","Farhan@123456", "dzvisual_homestay") or die(mysql_error());

	session_unset(); session_destroy(); session_start();
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- Meta, title, CSS, favicons, etc. -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Dzvisual Homestay </title>

    <!-- Bootstrap -->
    <link href="../vendors/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Font Awesome -->
    <link href="../vendors/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- NProgress -->
    <link href="../vendors/nprogress/nprogress.css" rel="stylesheet">
    <!-- Animate.css -->
    <link href="../vendors/animate.css/animate.min.css" rel="stylesheet">

    <!-- Custom Theme Style -->
    <link href="../build/css/custom.min.css" rel="stylesheet">
  </head>

  <body class="login">
    <div>
      <a class="hiddenanchor" id="signup"></a>
      <a class="hiddenanchor" id="signin"></a>

      <div class="login_wrapper">
        <div class="animate form login_form">
          <section class="login_content">
            <form method="post">
              <h1>Partner's Login</h1>
              <div>
                <input type="text" class="form-control" placeholder="Username" name="username" required />
              </div>
              <div>
                <input type="password" class="form-control" placeholder="Password" name="password" required />
              </div>
              <div>
				<button type="submit" class="btn btn-default submit" name="login">Login in</button>
              </div>

              <div class="clearfix"></div>

              <div class="separator">
                <div>
                  <h1><i class="fa fa-paw"></i> Dzvisual Homestay </h1>
                  2017 © Copyright Dzvisual homestay. All Rights Reserved. Design by <a href="http://www.dzvisual.my/">Dzvisual Network</a>
                </div>
              </div>
            </form>
			  
			  <a href="login.php"><button class="btn btn-primary">Switch to Admin's Login</button></a>
			  
			  
          </section>
        </div>
      </div>
    </div>
  </body>
</html>

<?php
	if(isset($_POST['login']))
	{
		$username=$_POST['username'];
		$password=$_POST['password'];
		
		$query = "SELECT * FROM owners WHERE o_username='$username' AND o_password='$password'";
		$result = mysqli_query($conn,$query);
		$row = mysqli_fetch_assoc($result);
		
		if(mysqli_num_rows($result)==1){
			$_SESSION['owner'][0] = $row['o_id']; //owner id
			$_SESSION['owner'][1] = $row['o_username']; //owner username
			$_SESSION['owner'][2] = $row['o_password']; //owner password
			$_SESSION['owner'][3] = $row['o_auth']; //owner authorization
			$_SESSION['owner'][4] = $row['o_name']; //owner anme
			$_SESSION['owner'][5] = $row['o_contact']; //owner contact
			
			header('Location: index.php?pagecontent=dashboard');
			
		//TELEGRAM NOTIFICATION
$messaggio = "OWNER/PARTNER ".$username." LOGGED IN

".$ipAddress;

sendMessage4($messaggio);
			
		}else{
			echo '<script type="text/javascript">';
			echo 'alert("unscccessful login")';
			echo '</script>';
		}
		
	}

	function sendMessage4($messaggio,$chatID = "26236173") {
		$token = "100033216:AAFpUx-vJZFa_8cFuw6RBmxGjqcN1spf3bU";
		
		echo "sending message to " . $chatID . "\n";

		$url = "https://api.telegram.org/bot" . $token . "/sendMessage?chat_id=" . $chatID;
		$url = $url . "&text=" . urlencode($messaggio);
		$ch = curl_init();
		$optArray = array(
				CURLOPT_URL => $url,
				CURLOPT_RETURNTRANSFER => true
		);
		curl_setopt_array($ch, $optArray);
		$result = curl_exec($ch);
		curl_close($ch);
		return $result;
	}

?>
