<?php
	define('thisscript','profil');

	require_once "global.php";
	
	if (empty($userid)){
		redirecting('home');
	}
	
	require_once "class/User.php";
	$user = new User();  
	
 	/* sanitize post, get, request */
	$_POST['do'] = ((empty($_POST['do']))?"":$_POST['do']);
	$_POST['regpassword'] = ((empty($_POST['regpassword']))?"":$_POST['regpassword']);
	$_REQUEST['id'] = ((empty($_REQUEST['id']))?"":$_REQUEST['id']);
	$_GET['action'] = ((empty($_GET['action']))?"":$_GET['action']);
	/* end sanitize */
  	 	
 	$password = '';
		
	$profil = $db->fetch_one("SELECT * FROM user WHERE userid = '".$db->clean($userid)."'");
 	$username = empty($profil['username'])?'':$profil['username'];
 	$email = empty($profil['email'])?'':$profil['email'];
	$firstname = empty($profil['firstname'])?'':$profil['firstname'];
	$companyname = empty($profil['companyname'])?'':$profil['companyname'];
	$companyphone = empty($profil['companyphone'])?'':$profil['companyphone'];
	$companyaddress = empty($profil['companyaddress'])?'':$profil['companyaddress'];
	$bbm = empty($profil['bbm']) ? '' : $profil['bbm'];
	$line = empty($profil['line']) ? '' : $profil['line'];
	$whatsapp = empty($profil['whatsapp']) ? '' : $profil['whatsapp'];
	$wechat = empty($profil['wechat']) ? '' : $profil['wechat'];
	$fb = empty($profil['fb']) ? '' : $profil['fb'];
	$twitter = empty($profil['twitter']) ? '' : $profil['twitter'];
	$instagram = empty($profil['instagram']) ? '' : $profil['instagram'];
	$imagePath = empty($profil['image_path']) ? '' : $profil['image_path'];
    $tradingAccount = empty($profil['trading_account']) ? '' : $profil['trading_account'];
    $tradingAccountPam = empty($profil['trading_account_pam']) ? '' : $profil['trading_account_pam'];
    $bonus = empty($profil['bonus_sharing']) ? 0 : number_format($profil['bonus_sharing'], 2, $decimalseparator, $thousandseparator);
    $bonus_point = empty($profil['bonus_point']) ? 0 : number_format($profil['bonus_point'], 2, $decimalseparator, $thousandseparator);
	$bank_id = empty($profil['bank_id'])?'':$profil['bank_id'];
	$bank_account = empty($profil['bank_account'])?'':$profil['bank_account'];
	$bank_account_name = empty($profil['bank_account_name'])?'':$profil['bank_account_name'];
	$bitcoin = empty($profil['bitcoin_acc'])?'':$profil['bitcoin_acc'];
	$userdetail['trading_account_amount'] = empty($userdetail['trading_account_amount']) ? 0 : $userdetail['trading_account_amount'];
	$max_sell = 0.01 * $userdetail['trading_account_pam_amount'];
	$max_sell = round($max_sell, 2);
	$max_sell = min($max_sell, $profil['bonus_point']);
	$userdetail['trading_account_amount'] = number_format($userdetail['trading_account_amount'], 2, $decimalseparator, $thousandseparator);
	$userdetail['trading_account_pam_amount'] = empty($userdetail['trading_account_pam_amount']) ? '' : number_format($userdetail['trading_account_pam_amount'], 2, $decimalseparator, $thousandseparator);
	$userdetail['eshare'] = empty($userdetail['eshare']) ? '' : number_format($userdetail['eshare'], 2, $decimalseparator, $thousandseparator);
	
	$bank_options = '<option value=""></option>';
	$db_bank = $db->fetch_all("SELECT bank_id, bankname FROM bank WHERE status = 1 AND bankname NOT LIKE '%Bitcoin%' ORDER BY bankname");
	if (sizeof($db_bank) > 0){
		foreach ($db_bank as $dbb){
			if($dbb['bank_id']!=27){
				$bank_options .= '<option value="'.$dbb['bank_id'].'"'.(($bank_id == $dbb['bank_id'])?' selected':'').'>'.$dbb['bankname'].'</option>';
			}
			
		}
	}
	
 	if (!empty($_POST)){
		$do = $_POST['do'];
 		if ($do == "editmember"){
			$name = empty($_POST['firstname'])?'':$_POST['firstname'];
			$companyname = empty($_POST['companyname'])?'':$_POST['companyname'];
			$companyphone = empty($_POST['companyphone'])?'':$_POST['companyphone'];
			$companyaddress = empty($_POST['companyaddress'])?'':$_POST['companyaddress'];
			$password = empty($_POST['regpassword'])?'':$_POST['regpassword'];
			$bbm = empty($_POST['bbm'])?'':$_POST['bbm'];
			$line = empty($_POST['line'])?'':$_POST['line'];
			$whatsapp = empty($_POST['whatsapp'])?'':$_POST['whatsapp'];
			$wechat = empty($_POST['wechat'])?'':$_POST['wechat'];
			$fb = empty($_POST['fb'])?'':$_POST['fb'];
			$twitter = empty($_POST['twitter'])?'':$_POST['twitter'];
			$instagram = empty($_POST['instagram'])?'':$_POST['instagram'];
            $tradingAccount = empty($_POST['trading_account']) ? '' : $_POST['trading_account'];
            $tradingAccountPam = empty($_POST['trading_account_pam']) ? '' : $_POST['trading_account_pam'];
            $bank_id = empty($_POST['bank_id']) ? '' : $_POST['bank_id'];
            $bank_account = empty($_POST['bank_account']) ? '' : $_POST['bank_account'];
            $bank_account_name = empty($_POST['bank_account_name']) ? '' : $_POST['bank_account_name'];
            $bitcoin_account = empty($_POST['bitcoin_account']) ? '' : $_POST['bitcoin_account'];
			$user->setId($userid);
			$user->updateProfil($password, $name, $companyname, $companyphone, $companyaddress, $bbm, $line, $whatsapp, $wechat, $fb, $twitter, $instagram, $tradingAccount, $tradingAccountPam, $bitcoin_account, $bank_id, $bank_account, $bank_account_name);
			redirecting("profile?msg=success");
 		}
	}
		
	require_once "incl/global_template.php";
	
	$tmpl = gettemplate('profil');
	eval("\$template = \"$tmpl\";");
	echo $template;
?>