10 changed files with 1490 additions and 1345 deletions
@ -0,0 +1,15 @@ |
|||||
|
<?php |
||||
|
require_once("../conn.php"); |
||||
|
|
||||
|
if(isset($_GET['contractid']) && $_GET['contractid']!=""){ |
||||
|
try{ |
||||
|
$id = $_GET["contractid"]; |
||||
|
$sql_str = "DELETE FROM contract_m_signed_back WHERE id = :contractid"; |
||||
|
$stmt = $conn->prepare($sql_str); |
||||
|
$stmt->bindParam(":contractid", $id); |
||||
|
$stmt->execute(); |
||||
|
header("HTTP/1.1 204 No Content"); |
||||
|
}catch(PDOException $e){ |
||||
|
die("ERROR!!!: ". $e->getMessage()); |
||||
|
} |
||||
|
} |
@ -0,0 +1,136 @@ |
|||||
|
<?php |
||||
|
require_once("../conn.php"); |
||||
|
include_once("./getFacilityNo.php"); |
||||
|
include_once("./getComboNo.php"); |
||||
|
include_once("./upload_chk.php"); |
||||
|
ini_set ( 'date.timezone' , 'Asia/Taipei' ); |
||||
|
|
||||
|
if($_SERVER['REQUEST_METHOD'] != 'POST'){ |
||||
|
exit(); |
||||
|
} |
||||
|
//新梯簽回 |
||||
|
if(isset($_POST["contractno"]) && $_POST["contractno"] != "" && isset($_POST['contracttype']) && $_POST['contracttype'] == 'm') { |
||||
|
try{ |
||||
|
$created_at = date('Y-m-d H:i:s'); |
||||
|
$created_by = $_POST["user_id"]; |
||||
|
$contractno = $_POST["contractno"]; |
||||
|
$customer = $_POST["customer"]; |
||||
|
$manager = $_POST["manager"]; |
||||
|
$vat = $_POST["vat"]; |
||||
|
$case_name = $_POST["case_name"]; |
||||
|
$linkman = $_POST["linkman"]; |
||||
|
$lm_tel = $_POST["lm_tel"]; |
||||
|
$address = $_POST["address"]; |
||||
|
$salesman = $_POST["salesman"]; |
||||
|
$contracttype = $_POST["contracttype"]; |
||||
|
$files = !empty($_FILES['files']) ? $_FILES['files'] : null; |
||||
|
$files_id = null; |
||||
|
|
||||
|
$fail_arr = []; |
||||
|
if(empty($contractno)) $fail_arr[] = '合約號為必填'; |
||||
|
if(empty($customer)) $fail_arr[] = '客戶名稱為必填'; |
||||
|
if(empty($manager)) $fail_arr[] = '負責人為必填'; |
||||
|
if(empty($vat)) $fail_arr[] = '統編/身分證為必填'; |
||||
|
if(empty($case_name)) $fail_arr[] = '案名為必填'; |
||||
|
if(empty($linkman)) $fail_arr[] = '聯絡人為必填'; |
||||
|
if(empty($lm_tel)) $fail_arr[] = '聯絡人電話為必填'; |
||||
|
if(empty($address)) $fail_arr[] = '地址為必填'; |
||||
|
if(empty($salesman)) $fail_arr[] = '營業員為必填'; |
||||
|
if(count($fail_arr) > 0) { |
||||
|
header("HTTP/1.1 422 Unprocessable Entity"); |
||||
|
echo json_encode($fail_arr); |
||||
|
exit(); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
$conn->beginTransaction(); |
||||
|
|
||||
|
$sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid ORDER BY create_at DESC"; |
||||
|
$stmt = $conn -> prepare($sql_str); |
||||
|
$stmt -> bindParam(":accountid",$salesman); |
||||
|
$stmt -> execute(); |
||||
|
$saleman = $stmt->fetch(PDO::FETCH_ASSOC); |
||||
|
$salesman_name = $saleman['name']; |
||||
|
if(!empty($files)){ |
||||
|
$englisharr = range('a', 'z'); |
||||
|
$files = $_FILES['files']; |
||||
|
$newfiles = []; |
||||
|
foreach( $files as $file ){ |
||||
|
$i = 0; //新陣列的索引編號 |
||||
|
foreach( $file as $key => $val ){ |
||||
|
$newfiles[$i]['name'] = $files['name'][$key]; |
||||
|
$newfiles[$i]['type'] = $files['type'][$key]; |
||||
|
$newfiles[$i]['tmp_name'] = $files['tmp_name'][$key]; |
||||
|
$newfiles[$i]['error'] = $files['error'][$key]; |
||||
|
$newfiles[$i]['size'] = $files['size'][$key]; |
||||
|
$i++; |
||||
|
} //foreach 第2層 end |
||||
|
} |
||||
|
$max_size = 4096*4096; //設定允許上傳檔案容量的最大值(1M) |
||||
|
$allow_ext = array('jpeg', 'jpg', 'png','JPG','JPEG','PNG','GIF'); //設定允許上傳檔案的類型 |
||||
|
$path = '../images/contracts/'; |
||||
|
if (!file_exists($path)) { mkdir($path); } |
||||
|
$msg_result = ''; //負責接收所有檔案檢測後的回傳訊息 |
||||
|
$datetime = (string)date('YmdHis'); |
||||
|
$files_id = 'm' . $datetime; // 保養=>b + 日期時間 |
||||
|
foreach( $newfiles as $key => $file ){ |
||||
|
$randNum = rand(1000,9999); |
||||
|
$randEnglish = $englisharr[rand(0,25)]; |
||||
|
$file_name = 'm' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum.$file['name']; |
||||
|
$msg = upload_chk( $file,$path, $max_size, $allow_ext, $file_name ); |
||||
|
if($msg==1){ |
||||
|
$msg = '檔案傳送成功!'; |
||||
|
$sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)"; |
||||
|
$stmt = $conn -> prepare($sql_str); |
||||
|
$stmt -> bindParam(':files_id' ,$files_id); |
||||
|
$stmt -> bindParam(':file_name' ,$file_name); |
||||
|
$stmt -> bindParam(':file_mime' ,$file['type']); |
||||
|
$stmt -> bindParam(':file_size' ,$file['size']); |
||||
|
$stmt -> bindParam(':created_at' ,$created_at); |
||||
|
$stmt -> bindParam(':created_by' ,$created_by); |
||||
|
$stmt ->execute(); |
||||
|
}else{ |
||||
|
throw new PDOException('檔案上傳失敗:' . $msg); |
||||
|
} |
||||
|
$msg_result .= '第' . ($key+1) . '個上傳檔案的結果:' . $msg . '<br/>'; |
||||
|
$src_name = $path.$file['name']; |
||||
|
if( file_exists($src_name) ){ |
||||
|
//副檔名 |
||||
|
$extname = pathinfo($src_name, PATHINFO_EXTENSION); |
||||
|
//主檔名 |
||||
|
$basename = basename($src_name, '.'.$extname); |
||||
|
} |
||||
|
} |
||||
|
}else{ |
||||
|
$files = null; |
||||
|
} |
||||
|
|
||||
|
$sql_str = "INSERT INTO contract_m_signed_back (contract_no, customer, manager, vat, case_name, linkman, lm_tel, address, salesman, salesman_name, files_id, created_at, created_by) VALUES (:contract_no, :customer, :manager, :vat, :case_name, :linkman, :lm_tel, :address, :salesman, :salesman_name, :files_id, :created_at, :created_by)"; |
||||
|
$stmt = $conn -> prepare($sql_str); |
||||
|
$stmt -> bindParam(":contract_no",$contractno); |
||||
|
$stmt -> bindParam(":customer",$customer); |
||||
|
$stmt -> bindParam(":manager",$manager); |
||||
|
$stmt -> bindParam(":vat",$vat); |
||||
|
$stmt -> bindParam(":case_name",$case_name); |
||||
|
$stmt -> bindParam(":linkman",$linkman); |
||||
|
$stmt -> bindParam(":lm_tel",$lm_tel); |
||||
|
$stmt -> bindParam(":address",$address); |
||||
|
$stmt -> bindParam(":salesman",$salesman); |
||||
|
$stmt -> bindParam(":salesman_name",$salesman_name); |
||||
|
$stmt -> bindParam(":files_id",$files_id); |
||||
|
$stmt -> bindParam(":created_at",$created_at); |
||||
|
$stmt -> bindParam(":created_by",$created_by); |
||||
|
$stmt -> execute(); |
||||
|
|
||||
|
|
||||
|
$result = $conn->commit(); |
||||
|
if($result){ |
||||
|
header("HTTP/1.1 201 Created"); |
||||
|
} |
||||
|
|
||||
|
}catch(PDOException $e){ |
||||
|
$conn->rollback(); |
||||
|
header("HTTP/1.1 500 Internal Server Error"); |
||||
|
die('Error!:'.$e->getMessage()); |
||||
|
} |
||||
|
} |
File diff suppressed because it is too large
Loading…
Reference in new issue