You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

144 lines
8.0 KiB

<?php
include "header.php";
if (isset($_POST['update'])) {
foreach ($_POST as $k => $v) {
$$k = htmlspecialchars(stripslashes(trim($v)));
}
//print_r($_POST);
//print_r($_FILES);exit;
$sql_atta = "";
$quantity = str_replace(",", "", $quantity);
$lead_time = str_replace(",", "", $lead_time);
$margin_day = str_replace(",", "", $margin_day);
if ($_FILES["attatch1"]["error"] == 0) {
$file_name = $_FILES["attatch1"]["name"];
$temp_file_name = $_FILES["attatch1"]["tmp_name"];
$file_size = $_FILES["attatch1"]["size"];
$target_dir = "bargain-uploads/";
$target_file1 = strtolower($target_dir.$bargainno."-1-".basename($file_name));
$img_file_type = pathinfo($file_name, PATHINFO_EXTENSION);
$upload_ok = 1;
//if (file_exists($target_file1)) unlink($target_file1);
foreach (glob($target_dir.$bargainno."-1-*") as $todelfile) {
unlink($todelfile);
}
$upload_res_1 = move_uploaded_file($temp_file_name, $target_file1);
$sql_atta .= "attatch1 = '$target_file1', ";
} else $target_file1 = "";
if ($_FILES["attatch2"]["error"] == 0) {
$file_name = $_FILES["attatch2"]["name"];
$temp_file_name = $_FILES["attatch2"]["tmp_name"];
$file_size = $_FILES["attatch2"]["size"];
$target_dir = "bargain-uploads/";
$target_file2 = strtolower($target_dir.$bargainno."-2-".basename($file_name));
$img_file_type = pathinfo($file_name, PATHINFO_EXTENSION);
$upload_ok = 1;
//if (file_exists($target_file2)) unlink($target_file2);
foreach (glob($target_dir.$bargainno."-2-*") as $todelfile) {
unlink($todelfile);
}
$upload_res_2 = move_uploaded_file($temp_file_name, $target_file2);
$sql_atta .= "attatch2 = '$target_file2', ";
} else $target_file2 = "";
if (($target_file1 && !$upload_res_1) || ($target_file2 && !$upload_res_2)) {
echo "<script type ='text/JavaScript'>";
echo "alert('檔案上傳失敗,請重新操作。');";
echo "location.href='bargain-index.php?function_name=bargain&".$token_link."';";
echo "</script>";
}
$db_query = "update bargain set receiver = '$receiver', response_dt = '$response_dt', item = '$item', annual = '$annual', urgent = '$urgent', ";
$db_query .= "vendor = '$vendor', prospecting = '$prospecting', category = '$category', dealer = '$dealer', reason = '$reason', brand = '$brand', ";
$db_query .= "model = '$model', quantity = '$quantity', brandkeep = '$brandkeep', lead_time = '$lead_time', margin = '$margin', margin_day = '$margin_day', ";
$db_query .= "acceptance = '$acceptance', purchase_history = '$purchase_history', item_description = '$item_description', repairno = '$repairno', ";
$db_query .= $sql_atta;
$db_query .= "category_repair = '$category_repair', content = '$content', quotation = '$quotation', create_dt = '$create_at' ";
$db_query .= "where id = '$id'";
$result = mysqli_query($link, $db_query);
$affected = mysqli_affected_rows($link);
if ($result && $sup_id_all != "") {
$bsid_arr = explode(",", $bsid_all);
$sup_id_arr = explode(",", $sup_id_all);
$supplier_arr = explode(",", rtrim($supplier_all, ","));
$quote_amt_be_arr = explode(",", $quote_amt_be_all);
$note_be_arr = explode(",", $note_be_all);
$quote_amt_ar_arr = explode(",", $quote_amt_ar_all);
$note_ar_arr = explode(",", $note_ar_all);
$item_no = 1;
// 有新增的供應商
$new_sup_cnt = count($supplier_arr) - count($bsid_arr);
if ($new_sup_cnt > 0) $next_sup_id = max($sup_id_arr)+1;
$idx = 0;
for ($i=0; $i<count($supplier_arr); $i++) {
if ($new_sup_cnt > 0 && $bsid_arr[$i] == "") { // 新增
$target_file_be = $target_file_ar = "";
if ($_FILES["supplier_attatch_be"]["name"]) { // 有上傳檔案
if ($_FILES["supplier_attatch_be"]["name"][$idx] && ($_FILES["supplier_attatch_be"]["error"][$idx] == 0)) {
$file_name = $_FILES["supplier_attatch_be"]["name"][$idx];
$temp_file_name = $_FILES["supplier_attatch_be"]["tmp_name"][$idx];
$file_size = $_FILES["supplier_attatch_be"]["size"][$idx];
$target_dir = "bargain-uploads/supplier/";
$target_file_be = strtolower($target_dir.$bargainno."-".$next_sup_id."-".basename($file_name));
$upload_ok = 1;
$img_file_type = pathinfo($target_file_be, PATHINFO_EXTENSION);
$upload_res_be = move_uploaded_file($temp_file_name, $target_file_be);
}
}
if ($_FILES["supplier_attatch_ar"]["name"]) { // 有上傳檔案
if ($_FILES["supplier_attatch_ar"]["name"][$idx] && ($_FILES["supplier_attatch_ar"]["error"][$idx] == 0)) {
$file_name = $_FILES["supplier_attatch_ar"]["name"][$idx];
$temp_file_name = $_FILES["supplier_attatch_ar"]["tmp_name"][$idx];
$file_size = $_FILES["supplier_attatch_ar"]["size"][$idx];
$target_dir = "bargain-uploads/supplier/";
$target_file_ar = strtolower($target_dir.$bargainno."-".$next_sup_id."-".basename($file_name));
$upload_ok = 1;
$img_file_type = pathinfo($target_file_ar, PATHINFO_EXTENSION);
$upload_res_ar = move_uploaded_file($temp_file_name, $target_file_ar);
}
}
if ($upload_res_be || $upload_res_ar) $idx++;
if (($target_file_be && !$upload_res_be) || ($target_file_ar && !$upload_res_ar)) {
echo "<script type ='text/JavaScript'>";
echo "alert('檔案上傳失敗,請重新操作!".$sql."');";
echo "location.href='bargain-index.php?function_name=bargain&".$token_link."';";
echo "</script>";
}
$db_query = "insert into bargain_supplier (bid, supplier_id, supplier, supplier_attatch_be, quote_amt_be, note_be, ";
$db_query .= "supplier_attatch_ar, quote_amt_ar, note_ar, creater, create_at) values (";
$db_query .= "'$id', '$next_sup_id', '$supplier_arr[$i]', '$target_file_be', '$quote_amt_be_arr[$i]', '$note_be_arr[$i]', ";
$db_query .= "'$target_file_ar', '$quote_amt_ar_arr[$i]', '$note_ar_arr[$i]', '$user_id', '$create_at')";
$result = mysqli_query($link, $db_query);
$next_sup_id++;
} else { // 修改(不支援重傳檔案)
$db_query = "update bargain_supplier set supplier = '$supplier_arr[$i]', quote_amt_be = '$quote_amt_be_arr[$i]', ";
$db_query .= "note_be = '$note_be_arr[$i]', quote_amt_ar = '$quote_amt_ar_arr[$i]', ";
$db_query .= "note_ar = '$note_ar_arr[$i]', create_at = '$create_at' ";
$db_query .= "where id = '$bsid_arr[$i]'";
$result = mysqli_query($link, $db_query);
}
}
}
mysqli_close($link);
if ($affected > 0) {
echo "<script type ='text/JavaScript'>";
echo "alert('update成功');";
echo "location.href='bargain-index.php?function_name=bargain&".$token_link."';";
echo "</script>";
} elseif ($affected == 0) {
echo "<script type ='text/JavaScript'>";
echo "alert('無新增資料');";
echo "location.href='bargain-index.php?function_name=bargain&".$token_link."';";
echo "</script>";
} else {
echo "{$db_query} 語法執行失敗,錯誤訊息SSS: " . mysqli_error($link);
}
}
?>