<?php session_start(); include "db_connection.php";

include "db_connection.php";
include_once("config.php");
include_once("includes/functions.php");

if(!$fbuser){
	$fbuser = null;
	$loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
	$output = '<a href="'.$loginUrl.'"><img src="images/fb_login.png"></a>'; 	
}else{
	$user_profile = $facebook->api('/me?fields=id,first_name,last_name,email,gender,locale,picture');
	$user = new Users();
	$user_data = $user->checkUser('facebook',$user_profile['id'],$user_profile['first_name'],$user_profile['last_name'],$user_profile['email'],$user_profile['gender'],$user_profile['locale'],$user_profile['picture']['data']['url']);
     }
	 
	 
	 
$chk=mysql_query("select * from users where email='".$_POST['email']."' and password='".$_POST['pass']."' and status='active'");
//echo "select * from users where email='".$_POST['email']."' and password='".$_POST['pass']."'";exit;
if(mysql_num_rows($chk)>0)
{

	$user=mysql_fetch_assoc($chk);
	 $_SESSION['user']=$user['uid'];
	 $_SESSION['name']=$user['name'];
		$_SESSION['email']=$user['email'];
		if(!empty($_SESSION['cart']))
		{
		?><script>window.location.href = 'checkout.php';</script><?php
		}
		else
		{
			?><script>window.location.href = 'index.php';</script><?php
		}
}
else
{
	echo "Email id or Password is Incorrect.";
}
?>