<?php 
session_start();
ob_start();
error_reporting (E_ALL ^ E_NOTICE);
// Include all the files 
include_once('connection.php');
include_once('messages.php');
include_once('functions.php');
include_once('path.php');
include_once('pagination.php');
date_default_timezone_set('Asia/Calcutta');
// Include all the classes 
function __autoload($class_name){
    require_once(DIR_MODAL.'/'.$class_name.'.php');
}
$conn = new connection();
$conn->connect();
$settingObj = new setting();
$userObj = new user();
$settings = $settingObj->getAllRecords();
if($settings && count($settings) > 0){
	foreach ($settings as $setting){
		define($setting->setting_name, $setting->setting_value);
	}
}
switch (basename($_SERVER['PHP_SELF'])){
	case 'index.php' :
				$meta_title = DEFAULT_META_TITLE;
				$meta_ketwords = DEFAULT_META_KEYWORD;
				$meta_descriptions = DEFAULT_META_DESCRIPTION;
			break;
			
	default:
				$meta_title = DEFAULT_META_TITLE;
				$meta_ketwords = DEFAULT_META_KEYWORD;
				$meta_descriptions = DEFAULT_META_DESCRIPTION;
	break;	
}
if(isset($_POST['loginHeader'])){
	if($_POST['userType'] == 'user')
		$type = 'Free';
	else
		$type = 'Paid';
		
	if($_POST['userName']!='' && $_POST['password']!=''){
		$result = $userObj->checkLogin($_POST['userName'],md5($_POST['password']),$type);
		if($result){		
			$_SESSION['user'] = $result;
			if($_POST['userType'] == 'user')
				$_SESSION['user']->type = 'user';
			else
				$_SESSION['user']->type = 'paid_user';
				
			$loginDetail->user_id = $_SESSION['user']->user_id;
			$loginDetail->login_ip = $_SERVER['REMOTE_ADDR'];
			$loginDetail->login_time = date('Y-m-d H:i:s');
			$rs = $userObj->updateLastLoginDate();
			header('location:'.SITE_URL);
			exit;
		}else{
			$failedLoginMsg = "Invalid username or password.";		
		}
	}else{
		$failedLoginMsg = "Username and password are required.";		
	}
}
?>