<?php
	session_start();
	
	require_once('Ultraviolet.php');
	require_once('Database.php');
	require('FormKey.php');

	$database =& DatabaseConnect::getInstance();
	$database->query("SET CHARACTER SET utf8");
	
	
	$salt = Ultraviolet::get('secret_key');
	
	if(!isset($_COOKIE['username']) || !isset($_COOKIE['password']))
	
	{
		header('location:../login.php');
		
		}
		
		else {
	
	$username = $_COOKIE['username'];
	$password = $_COOKIE['password'];
	
	

		
				
				$database->setBareQuery("SELECT user_fname, user_lname, user_type, id, user_email FROM admin_users WHERE user_name = '".$username."' AND user_pass = '".$password."'");
				$user_fname = $database->loadResultArray(0);
				$user_lname = $database->loadResultArray(1);
				$user_type = $database->loadResultArray(2);
				$user_id = $database->loadResultArray(3);
				$user_email = $database->loadResultArray(4);
				
				if(count($user_fname) > 0):
					$_SESSION['admin_username'] = $username;
					$_SESSION['admin_fname'] = $user_fname[0];
					$_SESSION['admin_lname'] = $user_lname[0];
					$_SESSION['admin_type'] = $user_type[0];
					$_SESSION['admin_id'] = $user_id[0];
					$_SESSION['admin_email'] = $user_email[0];
					
					
					
					header('location:../admin.php');
				else:
					header('location:../login.php?error=Lozinka koju ste uneli je pogrešna.<br/>Molimo pokušajte ponovo.');
				endif;



	
		}
?>