<?php

if(isset($_POST['depo'])){

	$_POST = help::sanitize($_POST);
	
	unset($_POST['depo']);
	
	$_POST['email'] = $__user['email'];
	$_POST['tnxid'] = uniqid('tnx');
	$_POST['rate'] = round((float)$_POST['rate'], 8);
	
	foreach( $_POST as $value ) {
		if( empty($value) ) $msg = "No field should be left empty!";
	};
	
	if( empty($msg) ):
		
		$sql = sQuery::insert( 'deposits', $_POST );

		if (mysqli_query($link, $sql)) {

			$msg = "
				Your order of {$_POST['usd']} USD worth of {$_POST['rate']} {$_POST['network']} has been sent. <br> 
				Your reference ID is {$_POST['tnxid']}. <br> 
				You  will be credited once your order is confirmed
			";
			
			$mailer = new mailer();
			$mailer->addAddress($__user['email']);
			$mailer->Subject = "New Deposit";
			
			$TABLE = $mailer->table(array(
				array("Reference", $_POST['tnxid']),
				array("Amount", "{$currency}{$_POST['usd']}"),
				array($_POST['network'], $_POST['rate']),
				array("status", "Pending")
			));
			
			$mailer->Body = "
				<section>
					Your {$_POST['network']} deposit order is being processed. Below are the information:
					{$TABLE}
				</section>
			";
			
			$mailer->send();
			

		} else $msg = "Error: " . $sql . "<br>" . mysqli_error($link);
	
	endif;

};


