<?php
require_once($_SERVER['DOCUMENT_ROOT']."/includes/SQLConnect.php"); 

require_once($_SERVER['DOCUMENT_ROOT'].'/includes/classes/PasswordHash.php');
require_once($_SERVER['DOCUMENT_ROOT'].'/includes/classes/CookieManager.php');



$ID = '';
if(isset($_COOKIE['ID']))
	$ID = $_COOKIE['ID'];

$hasher = new PasswordHash(8, FALSE);
$query = sprintf("SELECT password FROM `Users` WHERE ID='%s'",mysql_real_escape_string($ID));

$user = mysql_fetch_assoc(mysql_query($query));

$secretKey = 'fdasdKJKS7*32Mnbbhey$@kjhk888';
$manager = new BigOrNot_CookieManager($secretKey);

/*
if($manager->getCookieValue('password') != $user['password'])
	header("Location:http://".$_SERVER['SERVER_NAME']."/user_login.php");
*/

if(isset($_COOKIE['ID']) && (int)$_COOKIE['ID']>0){
	$query = sprintf("SELECT Users.*,Districts.state,Districts.district FROM `Users` LEFT JOIN `Districts` ON Users.district_ID = Districts.ID WHERE Users.ID='%d'",(int)$_COOKIE['ID']);
	$user_data = mysql_fetch_assoc(mysql_query($query));
	
	$result = mysql_query("SELECT Representatives.* FROM Representatives WHERE Representatives.district_ID = ".$user_data['district_ID']." AND Representatives.is_current_flag=1 AND Representatives.is_senator_flag=0");
	$representative = mysql_fetch_assoc($result);
}
?>
