<?php
/**
 * @package		Ad Platform
 * @author		Uta Marian - Alexandru ( -uMarian- )
 * @license		http://codecanyon.net/licenses
 * @link		http://www.uta-marian.com
 * @version		Version 1.0
 */

require_once(dirname(__FILE__).'/../../config.php');

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

if ( empty ( $code ) ) {
		$view->activation	=	'0';
} else {
	$validateCode	=	$db->Query("select user_id from junk_users where user_status=?","s",$code);

	if ( empty ( $validateCode ) ) {
		$view->activation	=	'1';
	} else {
		$view->activation	=	'2';
		//activate user account!
		
		$users	=	$db->Query("select `user_id`, `user_email`, `user_password` from junk_users where user_status=?","s",$code);
		$user_id		=	$users['0']['user_id'];
		$USER_ID_JUNK	=	$users['0']['user_id'];

		$junk_users_address	=	$db->Query("select `ua_country` from junk_users_address where ua_user_id=?","i",$user_id);

		$junk_users_profiles	=	$db->Query("select `up_first_name`, `up_last_name`, `up_birthday` from junk_users_profiles where up_user_id=?","i",$user_id);

		//** CREATE THE NEW USER ACCOUNT **//

		//** users **//
		$user_email		=	$users['0']['user_email'];
		$user_password	=	$users['0']['user_password'];
		$user_status	=	'1';
		$user_date		=	strtotime( "now" );
		
		$insert = $db->NoQuery("INSERT INTO users VALUES(NULL,?,?,?,?)","ssss",$user_email,$user_password,$user_status,$user_date);

			if ( $insert ) {
			$user_id	=	$db->LastID();


			//** users_address **//
			$ua_user_id		=	$user_id;
			$ua_country		=	$junk_users_address['0']['ua_country'];
			$ua_state		=	'';
			$ua_city		=	'';
			$ua_zip			=	'';
			$ua_address		=	'';
			$db->NoQuery("INSERT INTO users_address VALUES(?,?,?,?,?,?)","isssss",$ua_user_id,$ua_country,$ua_state,$ua_city,$ua_zip,$ua_address);
		
			//** users_profiles **//
			$up_user_id		=	$user_id;
			$up_first_name	=	$junk_users_profiles['0']['up_first_name'];
			$up_last_name	=	$junk_users_profiles['0']['up_last_name'];			
			$up_birthday	=	$junk_users_profiles['0']['up_birthday'];
			$up_phone		=	'';
			$up_tax_id		=	'';

			$db->NoQuery("INSERT INTO users_profiles VALUES(?,?,?,?,?,?)","ssssss",$up_user_id,$up_first_name,$up_last_name,$up_birthday,$up_phone,$up_tax_id);


			//** advertisers_profiles **//
			$adv_profile_user_id	=	$user_id;
			$adv_profile_deposits	=	'0';
			$adv_profile_spent		=	'0';
			$adv_profile_campaigns	=	'0';
			$adv_profile_ads		=	'0';

			$db->NoQuery("INSERT INTO advertisers_profiles VALUES(?,?,?,?,?)","sssss",$adv_profile_user_id,$adv_profile_deposits,$adv_profile_spent,$adv_profile_campaigns,$adv_profile_ads);



			//** publishers_profiles **//
			$pub_profile_user_id	=	$user_id;
			$pub_profile_money		=	'0';
			$pub_profile_ads		=	'0';
			$pub_profile_websites	=	'0';
			$pub_profile_channels	=	'0';

			$db->NoQuery("INSERT INTO publishers_profiles VALUES(?,?,?,?,?)","sssss",$pub_profile_user_id,$pub_profile_money,$pub_profile_ads,$pub_profile_websites,$pub_profile_channels);



			//*** REMOVE FROM JUNK DB ***//
				$db->NoQuery("DELETE FROM junk_users WHERE user_id=?","i",$USER_ID_JUNK);
				$db->NoQuery("DELETE FROM junk_users_address WHERE ua_user_id=?","i",$USER_ID_JUNK);
				$db->NoQuery("DELETE FROM junk_users_profiles WHERE up_user_id=?","i",$USER_ID_JUNK);


			} else {
		$view->activation	=	'0';
			}
	}
}



/* set page title */
$view->title = $LANG["WBS_ACT_TITLE"];
$view->description = $LANG["WBS_ACT_DETAILS"];
$view->keywords = $LANG["WBS_ACT_TAGS"];

//**DEFINE CUSTOM CSS/JS FILLES**//
$view->customCode = '<link href="'.HTTP_SERVER_WEBSITE.'templates/'.WEBSITE_TEMPLATE.'/assets/css/reglogin.css" rel="stylesheet">';

$view->header = $view->render(DIR_TEMPLATE.WEBSITE_TEMPLATE.'/header.php');
$view->footer = $view->render(DIR_TEMPLATE.WEBSITE_TEMPLATE.'/footer.php');

echo $view->render(DIR_TEMPLATE.WEBSITE_TEMPLATE.'/plugins/users/activation.php');
?>