include getenv("DOCUMENT_ROOT")."/include/session_include.php";
// Level 1 이하만 사용 가능
$func->checkLevelModal(1);
// Result Log
$GETDIR = getenv("DOCUMENT_ROOT");
$setDIRNAME = $GETDIR."/lib/log/".date('Ym');
$setFILENAME = $setDIRNAME."/".date("YmdHis").".log";
if (!is_dir($setDIRNAME)) {
mkdir($setDIRNAME, 0755, true);
}
$addCronLog = file_get_contents($setFILENAME);
$addCronLog .= "[upfilename=$upfilename][upfield=$upfield]\n";
// ################# 차후 uptype 에 따른 if 구분이 필요함
// echo "[action=$action]";
// log file upload
if ($mode == "insert" && $upfilename != "" && $upfield != "") {
$uploaddir = getenv("DOCUMENT_ROOT").'/upload/';
$existFlag = file_exists($uploaddir.$upfilename);
if (!file_exists($uploaddir.$upfilename)) {
echo "The file ".$uploaddir.$upfilename." does not exist";
}
//$rt = chmod ($uploaddir.$upfilename, 0755);
$lineCnt = 1;
$successRowCnt = 0;
if (($handle = fopen($uploaddir.$upfilename, "r")) !== FALSE) {
while (($getCSV = fgetcsv($handle, 2000, ",")) !== FALSE) {
if ($lineCnt >= 2) {
// Get customer Info
$d_accountno = str_replace(" ", "", trim($getCSV[0])); // d_accountno
$d_name = str_replace("\\", "", trim($getCSV[1])); // d_name
$updateTMP = str_replace("'", "''", trim($getCSV[3])); // update field
$qry_customer = "SELECT * FROM tbl_customer WHERE c_accountno = '".$d_accountno."' ";
$rt_customer = $jdb->fQuery($qry_customer, "query error");
//echo "[$qry_customer]
";
if ($rt_customer[0]) $fontColor = "black";
else $fontColor = "red";
if ($rt_customer[0]) {
if ($upfield == "c_status")
$qry = "UPDATE tbl_customer SET c_status='".$updateTMP."' WHERE c_accountno = '".$d_accountno."'";
else if ($upfield == "c_payableto")
$qry = "UPDATE tbl_customer SET c_payableto='".$updateTMP."' WHERE c_accountno = '".$d_accountno."'";
else if ($upfield == "c_paymenttype") {
$updateTMP = strtoupper($updateTMP);
$qry = "UPDATE tbl_customer SET c_paymenttype='".$updateTMP."' WHERE c_accountno = '".$d_accountno."'";
}
else if ($upfield == "c_paymentcycle")
$qry = "UPDATE tbl_customer SET c_paymentcycle='".$updateTMP."' WHERE c_accountno = '".$d_accountno."'";
else if ($upfield == "c_rate")
$qry = "UPDATE tbl_customer SET c_rate='".$updateTMP."' WHERE c_accountno = '".$d_accountno."'";
$jdb->nQuery($qry, "Update error");
//echo "[$qry]
";
$qry_customera = "SELECT * FROM tbl_customer WHERE c_accountno = '".$d_accountno."' ";
$rt_customera = $jdb->fQuery($qry_customera, "query error");
}
if ($updateTMP != $rt_customera[$upfield]) $fontColor = "#00DD37";
echo "[cnt=$lineCnt][ACCOUNTNO=$d_accountno][RNAME FILE/DB =".$d_name." / ".$rt_customer['c_name']."][".$upfield." FILE/DB/AFTER=".$updateTMP." / ".$rt_customer[$upfield]." / ".$rt_customera[$upfield]."]
";
$addCronLog .= "[cnt=$lineCnt][ACCOUNTNO=$d_accountno][RNAME FILE/DB =".$d_name." / ".$rt_customer['c_name']."][".$upfield." FILE/DB/AFTER=".$updateTMP." / ".$rt_customer[$upfield]." / ".$rt_customera[$upfield]."]\n";
}
//if ($lineCnt == 100) break;
$lineCnt++;
}
fclose($handle);
}
}
file_put_contents($setFILENAME, $addCronLog, FILE_APPEND);
?>