<?php

include getenv("DOCUMENT_ROOT")."/include/session_include.php";
include_once getenv("DOCUMENT_ROOT")."/lib/erp_api.php";

//$func->checkAdmin("index.php");

//echo "[$mode]";exit();


/*
for($i=0; $i<sizeof($_POST); $i++) {
	list($key, $value) = each($_POST);
	$$key = $value;

	if(is_array($value))
	{
		$count = 10;
		for($i = 0; $i < $count; $i ++) {
			if ($value[$i]) echo "ARRAY[$key][$value[$i]]<br>";
		}
	}
	else 	echo "[$key][$value]<br>";
	//print_r($_POST);
}

exit;
*/

if($c_uid == "") {
			echo 0;
			exit();
}

if ($_SESSION['ss_LEVEL'] == 10) {
			echo -1;
			exit();
}


$c_comment_riSTR = str_replace("\\", "", trim($c_comment_ri));
$c_locationSTR = str_replace("\\", "", trim($c_location));


$qry_customer = "UPDATE tbl_customer 
								SET 
									c_comment_ri = '".addslashes($c_comment_riSTR)."',
									c_location = '".addslashes($c_locationSTR)."',
									c_is_transfer = 'N'
								WHERE c_uid = '$c_uid' ";

//echo "[$qry_customer]<br>";

$jdb->nQuery($qry_customer, "update error");

// ====================
// Integration to ERP
// ====================
$erp = new ErpApi();

try {
	$columns = array();
	$values = array();
	$columns[] = "c_accountno";
	$columns[] = "c_comment_ri";
	$columns[] = "c_location";
	$values[] = $c_accountno;
	$values[] = addslashes($c_comment_riSTR);
	$values[] = addslashes($c_locationSTR);
	$lguserid = $_SESSION['ss_UID'];
	$erp->updateCustomerFromMis($columns, $values, $lguserid);

	// 성공 시 c_is_transfer='Y'
	$jdb->uQuery("tbl_customer", ["c_is_transfer"], ["Y"], " WHERE c_uid = ".(int)$_POST['id']);

} catch (Exception $e) {
	// 여기서는 아무것도 안함.
}

addLog ("add", "SHORT INFO", "UPDATE", $lguserid, $qry_customer, $c_uid);

echo 1;
exit();


?>