<?php
require_once(dirname(__FILE__).'/../../config.php');
require_once(DIR_SYSTEM.'/users/class.session.user.php');

$USER_ID	=	$_SESSION[USER_SESSION]['0']['user_id'];

$t	=	$prepare->sanitize($_GET['t'],'input');




if ( $t == 'profile' ) {
// users
$user_id		=	$USER_ID;
$user_email		=	$prepare->sanitize( $_POST['email'], 'input' );
$user_password	=	$prepare->sanitize( $_POST['password'], 'input' );

	//** UPDATE PASSWORD **//
	if ( !empty ( $user_password ) ) {
		$md5_pw	=	md5( $user_password );
		$db->NoQuery("UPDATE users SET user_password=? WHERE user_id=?","si",$md5_pw,$USER_ID);
	}



// users_profiles
$up_user_id		=	$USER_ID;
$up_first_name	=	$prepare->sanitize( $_POST['fname'], 'input' );
$up_last_name	=	$prepare->sanitize( $_POST['lname'], 'input' );

$month			=	$prepare->sanitize($_POST['month'],'input');
$day			=	$prepare->sanitize($_POST['day'],'input');
$year			=	$prepare->sanitize($_POST['year'],'input');

$up_birthday	=	strtotime(date('Y-m-d', strtotime($year.'-'.$month.'-'.$day)));;
$up_phone		=	$prepare->sanitize( $_POST['phone'], 'input' );
$up_tax_id		=	$prepare->sanitize( $_POST['tax_id'], 'input' );

	//** UPDATE USER PROFILE **//
	$update	=	$db->NoQuery("UPDATE users_profiles SET up_first_name=?, up_last_name=?, up_birthday=?, up_phone=?, up_tax_id=? WHERE up_user_id=?","sssssi",$up_first_name,$up_last_name,$up_birthday,$up_phone,$up_tax_id,$up_user_id);

// users_address
$ua_user_id	=	$USER_ID;
$ua_country	=	$prepare->sanitize( $_POST['location'], 'input' );
$ua_state	=	"";
$ua_city	=	$prepare->sanitize( $_POST['city'], 'input' );
$ua_zip		=	$prepare->sanitize( $_POST['zip'], 'input' );
$ua_address	=	$prepare->sanitize( $_POST['address'], 'input' );


	//** UPDATE ADDRESS **//
	$db->NoQuery("UPDATE users_address SET ua_country=?, ua_state=?, ua_city=?, ua_zip=?, ua_address=? WHERE ua_user_id=?","sssssi",$ua_country,$ua_state,$ua_city,$ua_zip,$ua_address,$ua_user_id);

	if ( $update ) {
		echo '<div id="mode">1</div>';
	} else {
		echo '<div id="mode">2</div>';
	}

}
















?>