<?php
class Users {
	public $table_name = 'tbl_users';
	
	function __construct(){
		//database configuration
		$dbServer = 'localhost'; //Define database server host
		$dbUsername = 'root'; //Define database username
		$dbPassword = 'XqhWRuFCiHs'; //Define database password
		$dbName = 'olxclone'; //Define database name
		
		//connect databse
		$con = mysqli_connect($dbServer,$dbUsername,$dbPassword,$dbName);
		if(mysqli_connect_errno()){
			die("Failed to connect with MySQL: ".mysqli_connect_error());
		}else{
			$this->connect = $con;
		}
	}
	
	function checkUser($oauth_provider,$oauth_uid,$fname,$lname,$email,$gender,$locale,$picture){
		
			
			
			$fullname=$fname." ".$lname;
			
			
			
			$select=mysql_query("select * from tbl_users where fullname='$fullname' and email='$email'");
			if(mysql_num_rows($select)>0)
			{
			$res=mysql_fetch_assoc($select);
			//$max1=$res['id'];
			$update=mysql_query("update tbl_users set fullname='$fullname',email='$email' where name='$fullname' and email='$email'");
			
			
			//session_start();
			$_SESSION['cid']=$res['userid'];
			$_SESSION['cname']=$fullname;
			$_SESSION['cemail']=$email;
		
		?><script>window.location="account_home";</script><?php
		
		}else{
			
			$select=mysql_query("select Max(userid) as idd from tbl_users");
			$res=mysql_fetch_assoc($select);
			
			$max1=($res['idd']+1);
			
			
			$fullname=$fname." ".$lname;
			$insertuser=mysql_query("insert into tbl_users (fullname,email)values('$fullname','$email')");
			
			$_SESSION['cid']=mysql_insert_id();
		  $_SESSION['cname']=$fullname;
		$_SESSION['cemail']=$email;
		
			?><script>window.location="account_home";</script><?php
		
		
		}
	
	}
}
?>