<?php
	define('thisscript','register-new-member');

	require_once "global.php";
	
	if (empty($userid)){
		redirecting('home');
	}
	
	$_GET['msg'] = empty($_GET['msg']) ? '' : $_GET['msg'];
	$_GET['u'] = ((empty($_GET['u']))?"":$_GET['u']);
	
	$_POST['do'] = ((empty($_POST['do']))?"":$_POST['do']);
	$_POST['agree'] = ((empty($_POST['agree']))?"":$_POST['agree']);
	$_POST['shipping'] = ((empty($_POST['shipping']))?"":$_POST['shipping']);
	$_POST['shipfirstname'] = ((empty($_POST['shipfirstname']))?"":$_POST['shipfirstname']);
	$_POST['shiplastname'] = ((empty($_POST['shiplastname']))?"":$_POST['shiplastname']);
	$_POST['scodes'] = ((empty($_POST['scodes']))?"":$_POST['scodes']);
	$_POST['username'] = ((empty($_POST['username']))?"":$_POST['username']);
	$_POST['regpassword'] = ((empty($_POST['regpassword']))?"":$_POST['regpassword']);
	$_POST['conpassword'] = ((empty($_POST['conpassword']))?"":$_POST['conpassword']);
	$_POST['firstname'] = ((empty($_POST['firstname']))?"":$_POST['firstname']);
	$_POST['lastname'] = ((empty($_POST['lastname']))?"":$_POST['lastname']);
	$_POST['email'] = ((empty($_POST['email']))?"":$_POST['email']);
	$_POST['phones'] = ((empty($_POST['phones']))?"":$_POST['phones']);
	$_POST['biladdress'] = ((empty($_POST['biladdress']))?"":$_POST['biladdress']);
	$_POST['bilcity'] = ((empty($_POST['bilcity']))?"":$_POST['bilcity']);
	$_POST['bilstate'] = ((empty($_POST['bilstate']))?"":$_POST['bilstate']);
	$_POST['bilcountry'] = ((empty($_POST['bilcountry']))?"":$_POST['bilcountry']);
	$_POST['bilpostal'] = ((empty($_POST['bilpostal']))?"":$_POST['bilpostal']);
	$_POST['shipaddress'] = ((empty($_POST['shipaddress']))?"":$_POST['shipaddress']);
	$_POST['shipcity'] = ((empty($_POST['shipcity']))?"":$_POST['shipcity']);
	$_POST['shipstate'] = ((empty($_POST['shipstate']))?"":$_POST['shipstate']);
	$_POST['shipcountry'] = ((empty($_POST['shipcountry']))?"":$_POST['shipcountry']);
	$_POST['shippostal'] = ((empty($_POST['shippostal']))?"":$_POST['shippostal']);
	$_POST['birthday'] = ((empty($_POST['birthday']))?"":$_POST['birthday']);
	$_POST['gender'] = ((empty($_POST['gender']))?"":$_POST['gender']);
	$_POST['cardnumber'] = ((empty($_POST['cardnumber']))?"":$_POST['cardnumber']);
	$_POST['typeofcard'] = ((empty($_POST['typeofcard']))?"":$_POST['typeofcard']);
	$_POST['newsletter'] = ((empty($_POST['newsletter']))?"":$_POST['newsletter']);
	
	$_POST['bbm'] = ((empty($_POST['bbm'])) ? "" : $_POST['bbm']);
	$_POST['whatsapp'] = ((empty($_POST['whatsapp'])) ? "" : $_POST['whatsapp']);
	$_POST['line'] = ((empty($_POST['line'])) ? "" : $_POST['line']);
	$_POST['wechat'] = ((empty($_POST['wechat'])) ? "" : $_POST['wechat']);
	$_POST['fb'] = ((empty($_POST['fb'])) ? "" : $_POST['fb']);
	$_POST['twitter'] = ((empty($_POST['twitter'])) ? "" : $_POST['twitter']);
	$_POST['instagram'] = ((empty($_POST['instagram'])) ? "" : $_POST['instagram']);
	
	$_POST['companyaddress'] = ((empty($_POST['companyaddress'])) ? "" : $_POST['companyaddress']);
	$_POST['companyphone'] = ((empty($_POST['companyphone'])) ? "" : $_POST['companyphone']);
	$_POST['companyname'] = ((empty($_POST['companyname'])) ? "" : $_POST['companyname']);
	$_POST['upline'] = ((empty($_POST['upline'])) ? "" : $_POST['upline']);
	/* end sanitize */
	
	$thisfirstname = $firstname;

	$username = '';
	$password = '';
	$firstname = '';
	$companyaddress = '';
	$companyname = '';
	$companyphone = '';
	$errmsg = '';
	$conpassword = '';
	$lastname = '';
	$email = '';
	$phones = '';
	$biladdress = '';
	$bilcity = '';
	$bilstate = '';
	$bilcountry = '';
	$bilpostal = '';
	$shipping = '';
	
	$shipfirstname = '';
	$shiplastname = '';
	$shipaddress = '';
	$shipcity = '';
	$shipstate = '';
	$shipcountry = '';
	$shippostal = '';
	
	$cardnumber = '';
	$birthday = '';
	$gender = '';
	$cardnumber = '';
	$typeofcard = '';
	$newsletter = '';
	
	$bbm = '';
	$whatsapp = '';
	$line = '';
	$wechat = '';
	$fb = '';
	$twitter = '';
	$instagram = '';
	
	$upline = '';
	
	if (!empty($_POST)){
		$do = $_POST['do'];
		$agree = $_POST['agree'];
		if ($do == "addmember"){
			session_start();
			$username = $_POST['username'];
			$bitcoin_acc = $_POST['bitcoin_account'];
			$password = $_POST['regpassword'];
			$conpassword = $_POST['conpassword'];
			$firstname = $_POST['firstname'];
			$lastname = $_POST['lastname'];
			$email = $_POST['email'];
			$phones = $_POST['phones'];
			$biladdress = $_POST['biladdress'];
			$bilcity = $_POST['bilcity'];
			$bilstate = $_POST['bilstate'];
			$bilcountry = $_POST['bilcountry'];
			$bilpostal = $_POST['bilpostal'];
			$shipping = $_POST['shipping'];
			
			$bbm = $_POST['bbm'];
			$whatsapp = $_POST['whatsapp'];
			$line = $_POST['line'];
			$wechat = $_POST['wechat'];
			$fb = $_POST['fb'];
			$twitter = $_POST['twitter'];
			$instagram = $_POST['instagram'];
			
			$companyaddress = $_POST['companyaddress'];
			$companyname = $_POST['companyname'];
			$companyphone = $_POST['companyphone'];
			
			$shipfirstname = $_POST['shipfirstname'];
			$shiplastname = $_POST['shiplastname'];
			$shipaddress = $_POST['shipaddress'];
			$shipcity = $_POST['shipcity'];
			$shipstate = $_POST['shipstate'];
			$shipcountry = $_POST['shipcountry'];
			$shippostal = $_POST['shippostal'];
			
			$birthday = $_POST['birthday'];
			$gender = $_POST['gender'];
			$cardnumber = $_POST['cardnumber'];
			$typeofcard = $_POST['typeofcard'];
			$newsletter = $_POST['newsletter'];
			
			$upline = $userid;
			
			$user->setId("");
			$cee = $user->checkEmailExist($email);
			
			$errmsg = '';
			if (empty($firstname)){
				$errmsg .= '<div align="left">- '. $phrase['fillusername'].'</div>';				
			}
			if (empty($email)){
				$errmsg .= '<div align="left">- '. $phrase['fillemail'].'</div>';				
			}
			else{
				if (!validateemail($email)){
					$errmsg .= '<div align="left">- '. $phrase['email_address_correctly'].'</div>';
				}
			}
			if (empty($companyphone)){
				$errmsg .= '<div align="left">- '. $phrase['fillcompanyphone'].'</div>';				
			}
			if (empty($password)){
				$errmsg .= '<div align="left">- '. $phrase['fillpassword'].'</div>';				
			}
			if (empty($conpassword)){
				$errmsg .= '<div align="left">- '. $phrase['passwordnullconfirmation'].'</div>';				
			}
			if (empty($firstname)){
				$errmsg .= '<div align="left">- '. $phrase['fillfirstname'].'</div>';				
			}
			if ($cee){
				$errmsg .= '<div align="left">- '. $phrase['already_fill_email'].'</div>';				
			}
			if ($password != $conpassword){
				$errmsg .= '<div align="left">- '. $phrase['passw_confirm'].'</div>';				
			}

			if (empty($errmsg)){
				$verified = 1;
				if ($registersetting['useverificationonregister']){
					$verified = 2;
				}
				
				$saveusergroup = 88;
				$parentid = 1;
				if(!empty($upline)){
					$parentid = $upline;
				}
				
				
				if (empty($typeofcard)){
					$cardnumber = '';
				}
				
				$fileName = '';
				
				$useridcreated = $user->createNewUser($username, $email, $fileName, $password, $firstname, $lastname, $phones, $bbm, $line, $whatsapp, $wechat, $fb, $twitter, $instagram, 0, $saveusergroup, $langid, getIP(), $verified, $birthday, $gender, $typeofcard, $cardnumber, $newsletter, $companyname, $companyaddress, $companyphone, $parentid, $bitcoin_acc);
				
				$user->setId($useridcreated);
				
				$user->saveAddress($biladdress,$bilcity,$bilstate,$bilcountry,$bilpostal,'billing');
			
				/* send verification email to user */
				$getuserdetail = $user->getUserDetail();
				$username = $getuserdetail['username'];
				$linkverification = '<a href="'.$general['siteurl'].'verification?u='.$useridcreated.'&v='.$getuserdetail['verificationcode'].'">'.$general['siteurl'].'verification?u='.$useridcreated.'&v='.$getuserdetail['verificationcode'].'</a>';
				$linkwebsite = '<a href="'.$general['siteurl'].'">'.$general['sitename'].'</a>';
				$linkemail = '<a href="mailto:'.$emailsetting['adminemail'].'">'.$emailsetting['adminemail'].'</a>';
				
				$toaddress = $emailsetting['adminemail'];
				$tocustomer = $email;
				
				$mailcontent = '
					Dear admin,<br /><br />
					There is a new User registered. The information are as below:
					<table width="100%" cellspacing="5" cellpadding="0">
					<tr>
						<td align="left" style="width: 150px;">Name</td>
						<td align="center">:</td>
						<td align="left">' . $firstname . '</td>
					</tr>
					<tr>
						<td align="left" style="width: 150px;">Phone Number</td>
						<td align="center">:</td>
						<td align="left">' . $companyphone . '</td>
					</tr>
					<tr>
						<td align="left" style="width: 150px;">Email</td>
						<td align="center">:</td>
						<td align="left">' . $email . '</td>
					</tr>
					</table>
				';
				
				$headers = "Content-type: text/html; charset=iso-8859-1\r\n";
				$headers .= "From: ".$general['sitename']." <".$general['siteemail'].">";
				$subject = $general['sitename'].' - New User Registered';
				$general['siteurl'] = 'http://evo-official.us/';
				$mailcontentcust = '
					Welcome To Evo-Official.us,<br /><br />
					You have been registered by '.$thisfirstname.' ('.$thisuseremail.'). Your information are as below:
					<table width="100%" cellspacing="5" cellpadding="0">
					<tr>
						<td align="left" style="width: 150px;">Name</td>
						<td align="center">:</td>
						<td align="left">' . $firstname . '</td>
					</tr>
					<tr>
						<td align="left" style="width: 150px;">Email Login</td>
						<td align="center">:</td>
						<td align="left">' . $email . '</td>
					</tr>
					<tr>
						<td align="left" style="width: 150px;">Phone Number</td>
						<td align="center">:</td>
						<td align="left">' . $companyphone . '</td>
					</tr>
					<tr>
						<td align="left" style="width: 150px;">Password</td>
						<td align="center">:</td>
						<td align="left">' . $password . '</td>
					</tr>
					</table>
					<br />
					You can login and change your password by clicking <a href="'.$general['siteurl'].'" target="_blank"><b>HERE</b></a>.
					<br />Please deposit to activate your account.
					<br /><br />
					Regards,<br />
					EVO Team Management
					<br />
					<img src="'.$general['siteurl'].'images/logo.png" border="0" style="vertical-align:middle;" height="100">
				';
				
				$subjectcust = 'Member Registration EVO';

				if ($emailsetting['enablesendmail']){
					mail($toaddress, $subject, $mailcontent, $headers);
					mail($tocustomer, $subjectcust, $mailcontentcust, $headers);
				}
				
				redirecting("register-new-member?msg=success");
			}
		}
	}
		
	require_once "incl/global_template.php";
	
	$tmpl = gettemplate('register-new-member');
	eval("\$template = \"$tmpl\";");
	echo $template;
?>