date("Y-m-d H:i:s"))); $db_query = sprintf("UPDATE ngfeedback SET %s WHERE id = ?", implode(",", array_map( function ($_k) { return sprintf("%s = ?", $_k); }, array_keys($data) ) )); $stmt = $link->prepare($db_query); // 此處僅有字串格式 $stmt->bind_param(implode("", array_fill(0, count($data) + 1, "s")), ...array_values(array_merge($data, array("id" => $_POST["no"])))); $stmt->execute(); if (mysqli_affected_rows($link) > 0) { echo ""; //header("Location: pricereview-index.php"); } else { echo ""; } } else { $data = array_reduce(array( "responsibledepartment", "investigationreason", "countermeasure", "verify" ), function ($acc, $key) use ($input) { switch ($key) { default: $acc[$key] = htmlspecialchars(stripslashes(trim($input[$key]))) ?: null; } return $acc; }, array("progress" => "1", "update_at" => date("Y-m-d H:i:s"))); if ($data["responsibledepartment"]) { $db_query = "SELECT accountid FROM account WHERE department_id = ? ORDER BY role_id ASC, create_at DESC LIMIT 0 , 1"; $stmt = $link->prepare($db_query); // 此處僅有字串格式 $stmt->bind_param("s", $data["responsibledepartment"]); $stmt->execute(); $result = $stmt->get_result(); $uarr = mysqli_fetch_assoc($result); $data["responsibledepartmentleader"] = isset($uarr["accountid"]) ? $uarr["accountid"] : null; // 責任單位回覆人預設主管 $data["responder"] = isset($uarr["accountid"]) ? $uarr["accountid"] : null; } if ($data["responsibledepartmentleader"]) { $db_query = sprintf("UPDATE ngfeedback SET %s WHERE id = ?", implode(",", array_map( function ($_k) { return sprintf("%s = ?", $_k); }, array_keys($data) ) )); $stmt = $link->prepare($db_query); // 此處僅有字串格式 $stmt->bind_param(implode("", array_fill(0, count($data) + 1, "s")), ...array_values(array_merge($data, array("id" => $_POST["no"])))); $stmt->execute(); if (mysqli_affected_rows($link) > 0) { echo ""; //header("Location: pricereview-index.php"); } else { echo ""; } } else { echo ""; } } } ?>