<?php 
session_start();

if (!isset($_SESSION['projecta_admin']) && !preg_match("/login.php/i",$_SERVER['REQUEST_URI']))
{
	header('location: login.php');
}

include_once 'config.php';
require_once 'includes/class.database.php';
require_once 'includes/class.admins.php';
require_once 'includes/class.projects.php';
require_once 'includes/class.issue-types.php';
require_once 'includes/class.issues.php';
require_once 'includes/class.tasks.php';
require_once 'includes/class.drafts.php';
require_once 'includes/functions.php';

$success=$error="";

$admin= new ManageAdmins();
$project= new ManageProjects();
$issuetype= new ManageIssueTypes();
$issue= new ManageIssues();
$task= new ManageTasks();
$draft= new ManageDrafts();

$db_connection = new dbConnection();
$dbConTest=$db_connection->connect();
$type=gettype($dbConTest);
if ($type==="integer") {
	if($dbConTest==0)
	{
		header('Location: ./install');
		die();
	}
}


$projecnames = $project->GetList();

// Check Kardan Mohtavaye Session
if (isset($_SESSION['projecta_admin'])) 
{
	$session_content = explode(':',$_SESSION['projecta_admin']);
	if($admin->AdminLogin($session_content[0],$session_content[1])!=1)
		header('location: logout.php');
		
	if (isset($_SESSION['user_last_ip'])===false) 
		$_SESSION['user_last_ip'] = $_SERVER['REMOTE_ADDR'];
	
	if ($_SESSION['user_last_ip'] !== $_SERVER['REMOTE_ADDR']) 
		header('location: logout.php');

	//Read User Informaton base on Username	
	$user=$session_content[0];
	$admininfo=$admin->Getinfo("ausername",$user);

	//Admin Activity Status Check
	if ($admininfo['0']['aactive']==0)
	  header('location: logout.php');

	//Admin Expiration Date Check
	if ($admininfo['0']['aexpiration_date']!="") 
	{
		$aid=$admininfo['0']['aid'];
		$aexpiration_date=$admininfo['0']['aexpiration_date'];
		date_default_timezone_set('UTC');
		$var = "$aexpiration_date 00:00:00.0";
		$today = date("Y-m-d H:i:s");
		if ($today>$var)
		{
			// $admin->SetDeactive($aid);
			header('location: logout.php');
		}
	}

}

 ?>