<?
	// echo "____________________________________________\n";
	// var_dump($_POST);
	// echo $_POST['JSON'];
	include('_functions2.php');
	$data=json_decode($_POST['JSON'],true);
	$order = (string)$data['cert']['orderid'];
	$label = (string)$data['cert']['label'];
	$num = str_replace( $order,'', $label );
	$int = (int)$num;
	$count = (string)$int;
	$count = (int)$int;
	$emailtype = (int)$data['cert']['emailtype'];
	$cardtype = (int)$data['cert']['cardtype'];

	$cards = (string)$data['form']['cards'];
	$countNew = explode( ',', $cards );
	

	// echo $count;

	echo 'guid: ' . $data['cert']['guid'] . "\n";
	echo 'email: ' . $data['form']['email'] . "\n";
	echo 'order: ' . $data['cert']['orderid'] . "\n";
	echo 'count: ' . $count . "\n";
	echo 'first: ' . $data['form']['first'] . "\n";
	echo 'last: ' . $data['form']['last'] . "\n";
	echo 'from: ' . $data['form']['from'] . "\n";
	echo 'message: ' . $data['form']['message'] . "\n";
	echo 'value: ' . $data['cert']['dvalue'] . "\n";
	echo 'tip: ' . $data['cert']['tip'] . "\n";
	echo 'emailtype: ' . $data['cert']['emailtype'] . "\n";

	echo emailCustomer( $data['cert']['guid'], $data['form']['email'], $data['cert']['orderid'], $countNew, $data['form']['first'], $data['form']['last'], $emailtype, $data['form']['from'], $data['form']['message'], $data['cert']['dvalue'], $data['cert']['tip'], $cardtype, true );


			foreach ($countNew as $x) {

			    $ecard_number = $order . '' . padZero($x);

			    
				$query = " UPDATE _reph_report_cache SET esend=1 WHERE ecard_number='$ecard_number'; ";
				dbquery($query,true);


			}


?>