<?

include('_functions2.php');
$JSON=json_decode($_POST['JSON'],true);
	$order=($_POST['order']);
	$count=($_POST['count']);
	$dval=($_POST['dvalue']);

	$result = "";

$i = 0;
foreach($JSON as $item) {
	$id=$item[field_id];
	$first=($item['first']);
	$last=($item['last']);
	$email=($item['email']);
	$certificate=($item['certificate']);
	$del=($item['action_del']);
	$status=($item['status']);
	$dvalue=($item['dvalue']);

	$from=($item['from']);
	$message=($item['message']);
	$hasmessage=($item['hasmessage']);

	$tip=($item['tip']);
	$card=($item['card']);
	$esend=($item['esend']);

	$gift=($item['gift']);


	if ($status === 'success') {} else {
		if ($id === 'null') {$id=0;}
		if ($first === 'null') {$first='';}
		if ($last === 'null') {$last='';}
		if ($email === 'null') {$email='';}
		if ($certificate === 'null') {$certificate='';}

		if ($del === 'Y' && $id !== '0' && $id !== 0) {
		} else if ($del === 'N' && ($id === '0' || $id === 0)) {

			$guid = getGUID();


			$theType = 99;
			if ($esend === 1 || $esend === '1') {
				if ($gift === 1 || $gift === '1') {
					if ($hasmessage === 1 || $hasmessage === '1') {
						$result .= emailCustomer($guid, $email, $order, $certificate, $first, $last, 1, $from, $message, $dvalue, $tip, $card, false);
						$theType = 1;
					} else {
						$result .= emailCustomer($guid, $email, $order, $certificate, $first, $last, 3, '', '', $dvalue, $tip, $card, false);
						$theType = 3;
						$from = '';
						$message = '';
					}
					
				} else {
					$result .= emailCustomer($guid, $email, $order, $certificate, $first, $last, 0,'','', $dvalue, $tip, $card, false);
					$theType = 0;
					$from = '';
					$message = '';
				}



			} 

		} else {

		}
	}

	$i++;

}
echo $result;
?>