<?
// include('../functionsLoader.php');
// dbopen();
// $guid=$_POST['guid'];
include('_functions.php');
$JSON=json_decode($_POST['JSON'],true);
// $date_created = getToday();
	$order=($_POST['order']);
	$count=($_POST['count']);
	$dval=($_POST['dvalue']);
	$orderid = addOrder(getGUID(), $order, $dval, false);
$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']);
	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) {
			// $query = "DELETE  FROM profile_edu WHERE id='$id'";
			// mysql_query($query);
		} else if ($del === 'N' && ($id === '0' || $id === 0)) {

			// echo "$first $last $email $certificate \n";
			$guid = getGUID();
			// echo $order . ' X ' . $certificate . "\n";
			addCertificateGroup($guid, $order, $first, $last, $email, $certificate, $dvalue, false);
			$JSON[$i]['status'] = emailCustomer($guid, $email, $order, $certificate, $first, $last, false,'','', $dvalue);
			// if ($JSON[$i]['status'] === 'success') {}
		} else {
			// $query = "
			// 	UPDATE profile_edu
			// 	SET 
			// 	degree='$degree',
			// 	school='$school',
			// 	major='$major',
			// 	year='$year'
			// 	WHERE id='$id'";
			// mysql_query($query);
		}
	}

	$i++;

}
$result = json_encode($JSON);
echo $result;
//mysql_query($query2);

// dbclose();
?>