From 9584156f9a21f6725580b7f8974b8f9575fe83c8 Mon Sep 17 00:00:00 2001 From: NAS-Admin Date: Sun, 8 Feb 2026 18:10:54 +0900 Subject: [PATCH] =?UTF-8?q?=EC=98=A4=ED=98=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.php | 298 ++++++++++++++++++++++++++-- cards.php | 85 +++++++- db_init.php | 90 +++++++-- laptops.php | 380 ++++++++++++++++++++++++++++------- mfp.php | 86 +++++++- models.php | 559 ++++++++++++++++++++++++++++++++++++++++++++++------ nav.php | 2 +- rental.php | 308 +++++++++++++++++++++++++++++ 8 files changed, 1618 insertions(+), 190 deletions(-) create mode 100644 rental.php diff --git a/api.php b/api.php index 5699898..b2e7bd4 100644 --- a/api.php +++ b/api.php @@ -101,6 +101,37 @@ try { echo json_encode($db->query($query)->fetchAll()); break; + case 'get_rental_laptops': + $query = "SELECT a.*, m.model_name, m.manufacturer, m.product_name + FROM laptop_assets a + LEFT JOIN laptop_models m ON a.model_id = m.id + WHERE a.assigned_user_name LIKE '%업무용%'"; + echo json_encode($db->query($query)->fetchAll()); + break; + + case 'update_rental': + $data = json_decode(file_get_contents('php://input'), true); + $stmt = $db->prepare("UPDATE laptop_assets SET rental_user_name = ? WHERE id = ?"); + $stmt->execute([$data['rental_user_name'], $data['id']]); + + // Log the rental action + if ($data['rental_user_name']) { + $log_stmt = $db->prepare("INSERT INTO asset_history (asset_id, log_type, user_name, action_date) VALUES (?, 'rental', ?, ?)"); + $log_stmt->execute([$data['id'], $data['rental_user_name'], date('Y-m-d')]); + } + echo json_encode(['success' => true]); + break; + + case 'get_asset_history': + $asset_id = $_GET['asset_id']; + $rental_logs = $db->query("SELECT * FROM asset_history WHERE asset_id = $asset_id AND log_type = 'rental' ORDER BY id DESC LIMIT 20")->fetchAll(); + $assign_logs = $db->query("SELECT * FROM asset_history WHERE asset_id = $asset_id AND log_type = 'assignment' ORDER BY id DESC LIMIT 20")->fetchAll(); + echo json_encode([ + 'rental' => $rental_logs, + 'assignment' => $assign_logs + ]); + break; + case 'get_cards': echo json_encode($db->query("SELECT * FROM access_cards")->fetchAll()); break; @@ -143,15 +174,66 @@ try { case 'add_model': $data = json_decode(file_get_contents('php://input'), true); - $stmt = $db->prepare("INSERT INTO laptop_models (model_name, manufacturer, specs) VALUES (?, ?, ?)"); - $stmt->execute([$data['model_name'], $data['manufacturer'], $data['specs'] ?? '']); + $stmt = $db->prepare("INSERT INTO laptop_models ( + model_name, manufacturer, specs, cpu, npu, hdd0_model, hdd0_capacity, + hdd1_model, hdd1_capacity, ram, asset_status, assigned_user, fixed_ip, + remarks, options, power_rating, purchase_date, vendor, product_name + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + $stmt->execute([ + $data['model_name'], + $data['manufacturer'], + $data['specs'] ?? '', + $data['cpu'] ?? '', + $data['npu'] ?? '', + $data['hdd0_model'] ?? '', + $data['hdd0_capacity'] ?? '', + $data['hdd1_model'] ?? '', + $data['hdd1_capacity'] ?? '', + $data['ram'] ?? '', + $data['asset_status'] ?? '', + $data['assigned_user'] ?? '', + $data['fixed_ip'] ?? '', + $data['remarks'] ?? '', + $data['options'] ?? '', + $data['power_rating'] ?? '', + $data['purchase_date'] ?? '', + $data['vendor'] ?? '', + $data['product_name'] ?? '' + ]); echo json_encode(['success' => true]); break; case 'update_model': $data = json_decode(file_get_contents('php://input'), true); - $stmt = $db->prepare("UPDATE laptop_models SET model_name = ?, manufacturer = ?, specs = ? WHERE id = ?"); - $stmt->execute([$data['model_name'], $data['manufacturer'], $data['specs'] ?? '', $data['id']]); + $stmt = $db->prepare("UPDATE laptop_models SET + model_name = ?, manufacturer = ?, specs = ?, cpu = ?, npu = ?, + hdd0_model = ?, hdd0_capacity = ?, hdd1_model = ?, hdd1_capacity = ?, + ram = ?, asset_status = ?, assigned_user = ?, fixed_ip = ?, + remarks = ?, options = ?, power_rating = ?, purchase_date = ?, + vendor = ?, product_name = ? + WHERE id = ?"); + $stmt->execute([ + $data['model_name'], + $data['manufacturer'], + $data['specs'] ?? '', + $data['cpu'] ?? '', + $data['npu'] ?? '', + $data['hdd0_model'] ?? '', + $data['hdd0_capacity'] ?? '', + $data['hdd1_model'] ?? '', + $data['hdd1_capacity'] ?? '', + $data['ram'] ?? '', + $data['asset_status'] ?? '', + $data['assigned_user'] ?? '', + $data['fixed_ip'] ?? '', + $data['remarks'] ?? '', + $data['options'] ?? '', + $data['power_rating'] ?? '', + $data['purchase_date'] ?? '', + $data['vendor'] ?? '', + $data['product_name'] ?? '', + $data['id'] + ]); echo json_encode(['success' => true]); break; @@ -172,22 +254,11 @@ try { case 'add_laptop_asset': $data = json_decode(file_get_contents('php://input'), true); - $stmt = $db->prepare("INSERT INTO laptop_assets (asset_tag, model_id, current_user_id, status, serial_number, purchase_date, ip_address) VALUES (?, ?, ?, ?, ?, ?, ?)"); - $stmt->execute([ - $data['asset_tag'], - $data['model_id'], - $data['current_user_id'] ?: null, - $data['current_user_id'] ? 'assigned' : 'stock', - $data['serial_number'], - $data['purchase_date'], - $data['ip_address'] ?? null - ]); - echo json_encode(['success' => true]); - break; - - case 'update_laptop_asset': - $data = json_decode(file_get_contents('php://input'), true); - $stmt = $db->prepare("UPDATE laptop_assets SET asset_tag = ?, model_id = ?, current_user_id = ?, status = ?, serial_number = ?, purchase_date = ?, ip_address = ? WHERE id = ?"); + $stmt = $db->prepare("INSERT INTO laptop_assets ( + asset_tag, model_id, current_user_id, status, serial_number, purchase_date, ip_address, + cpu, npu, hdd0_model, hdd0_capacity, hdd1_model, hdd1_capacity, ram, + asset_status, assigned_user_name, fixed_ip, options, power_rating, manufacturer, vendor, product_name, remarks, last_confirmed_date + ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->execute([ $data['asset_tag'], $data['model_id'], @@ -196,8 +267,79 @@ try { $data['serial_number'], $data['purchase_date'], $data['ip_address'] ?? null, + $data['cpu'] ?? '', + $data['npu'] ?? '', + $data['hdd0_model'] ?? '', + $data['hdd0_capacity'] ?? '', + $data['hdd1_model'] ?? '', + $data['hdd1_capacity'] ?? '', + $data['ram'] ?? '', + $data['asset_status'] ?? '', + $data['assigned_user_name'] ?? '', + $data['fixed_ip'] ?? '', + $data['options'] ?? '', + $data['power_rating'] ?? '', + $data['manufacturer'] ?? '', + $data['vendor'] ?? '', + $data['product_name'] ?? '', + $data['remarks'] ?? '', + $data['last_confirmed_date'] ?? null + ]); + $new_asset_id = $db->lastInsertId(); + if ($data['assigned_user_name']) { + $log_stmt = $db->prepare("INSERT INTO asset_history (asset_id, log_type, user_name, action_date) VALUES (?, 'assignment', ?, ?)"); + $log_stmt->execute([$new_asset_id, $data['assigned_user_name'], date('Y-m-d')]); + } + echo json_encode(['success' => true]); + break; + + case 'update_laptop_asset': + $data = json_decode(file_get_contents('php://input'), true); + + // Get old data for logging comparison + $old_stmt = $db->prepare("SELECT assigned_user_name FROM laptop_assets WHERE id = ?"); + $old_stmt->execute([$data['id']]); + $old_asset = $old_stmt->fetch(); + + $stmt = $db->prepare("UPDATE laptop_assets SET + asset_tag = ?, model_id = ?, current_user_id = ?, status = ?, serial_number = ?, purchase_date = ?, ip_address = ?, + cpu = ?, npu = ?, hdd0_model = ?, hdd0_capacity = ?, hdd1_model = ?, hdd1_capacity = ?, ram = ?, + asset_status = ?, assigned_user_name = ?, fixed_ip = ?, options = ?, power_rating = ?, manufacturer = ?, vendor = ?, product_name = ?, remarks = ?, last_confirmed_date = ? + WHERE id = ?"); + $stmt->execute([ + $data['asset_tag'], + $data['model_id'], + $data['current_user_id'] ?: null, + $data['current_user_id'] ? 'assigned' : 'stock', + $data['serial_number'], + $data['purchase_date'], + $data['ip_address'] ?? null, + $data['cpu'] ?? '', + $data['npu'] ?? '', + $data['hdd0_model'] ?? '', + $data['hdd0_capacity'] ?? '', + $data['hdd1_model'] ?? '', + $data['hdd1_capacity'] ?? '', + $data['ram'] ?? '', + $data['asset_status'] ?? '', + $data['assigned_user_name'] ?? '', + $data['fixed_ip'] ?? '', + $data['options'] ?? '', + $data['power_rating'] ?? '', + $data['manufacturer'] ?? '', + $data['vendor'] ?? '', + $data['product_name'] ?? '', + $data['remarks'] ?? '', + $data['last_confirmed_date'] ?? null, $data['id'] ]); + + // Auto-log assignment change + if ($data['assigned_user_name'] && $data['assigned_user_name'] !== ($old_asset['assigned_user_name'] ?? '')) { + $log_stmt = $db->prepare("INSERT INTO asset_history (asset_id, log_type, user_name, action_date) VALUES (?, 'assignment', ?, ?)"); + $log_stmt->execute([$data['id'], $data['assigned_user_name'], date('Y-m-d')]); + } + echo json_encode(['success' => true]); break; @@ -231,6 +373,122 @@ try { echo json_encode(['success' => true]); break; + case 'bulk_update_laptops': + $data = json_decode(file_get_contents('php://input'), true); + $ids = $data['ids']; + $newStatus = $data['status'] ?? null; + $newModelId = $data['model_id'] ?? null; + if (empty($ids)) { + echo json_encode(['success' => false, 'error' => 'No items selected']); + break; + } + $updates = []; + $params = []; + if ($newStatus) { + $updates[] = "status = ?"; + $params[] = $newStatus; + } + if ($newModelId) { + $updates[] = "model_id = ?"; + $params[] = $newModelId; + } + if (empty($updates)) { + echo json_encode(['success' => false, 'error' => 'No updates specified']); + break; + } + $sql = "UPDATE laptop_assets SET " . implode(", ", $updates) . " WHERE id IN (" . implode(",", array_fill(0, count($ids), "?")) . ")"; + $stmt = $db->prepare($sql); + $stmt->execute(array_merge($params, $ids)); + echo json_encode(['success' => true]); + break; + + case 'bulk_update_cards': + $data = json_decode(file_get_contents('php://input'), true); + $ids = $data['ids']; + $newStatus = $data['status'] ?? null; + $newCardType = $data['card_type'] ?? null; + if (empty($ids)) { + echo json_encode(['success' => false, 'error' => 'No items selected']); + break; + } + $updates = []; + $params = []; + if ($newStatus) { + $updates[] = "status = ?"; + $params[] = $newStatus; + } + if ($newCardType) { + $updates[] = "card_type = ?"; + $params[] = $newCardType; + } + if (empty($updates)) { + echo json_encode(['success' => false, 'error' => 'No updates specified']); + break; + } + $sql = "UPDATE access_cards SET " . implode(", ", $updates) . " WHERE id IN (" . implode(",", array_fill(0, count($ids), "?")) . ")"; + $stmt = $db->prepare($sql); + $stmt->execute(array_merge($params, $ids)); + echo json_encode(['success' => true]); + break; + + case 'bulk_update_mfp': + $data = json_decode(file_get_contents('php://input'), true); + $ids = $data['ids']; + $newStatus = $data['status'] ?? null; + $newPurpose = $data['purpose'] ?? null; + if (empty($ids)) { + echo json_encode(['success' => false, 'error' => 'No items selected']); + break; + } + $updates = []; + $params = []; + if ($newStatus) { + $updates[] = "status = ?"; + $params[] = $newStatus; + } + if ($newPurpose) { + $updates[] = "purpose = ?"; + $params[] = $newPurpose; + } + if (empty($updates)) { + echo json_encode(['success' => false, 'error' => 'No updates specified']); + break; + } + $sql = "UPDATE mfp_accounts SET " . implode(", ", $updates) . " WHERE id IN (" . implode(",", array_fill(0, count($ids), "?")) . ")"; + $stmt = $db->prepare($sql); + $stmt->execute(array_merge($params, $ids)); + echo json_encode(['success' => true]); + break; + + case 'bulk_update_models': + $data = json_decode(file_get_contents('php://input'), true); + $ids = $data['ids']; + $newManufacturer = $data['manufacturer'] ?? null; + $newProductName = $data['product_name'] ?? null; + if (empty($ids)) { + echo json_encode(['success' => false, 'error' => 'No items selected']); + break; + } + $updates = []; + $params = []; + if ($newManufacturer) { + $updates[] = "manufacturer = ?"; + $params[] = $newManufacturer; + } + if ($newProductName) { + $updates[] = "product_name = ?"; + $params[] = $newProductName; + } + if (empty($updates)) { + echo json_encode(['success' => false, 'error' => 'No updates specified']); + break; + } + $sql = "UPDATE laptop_models SET " . implode(", ", $updates) . " WHERE id IN (" . implode(",", array_fill(0, count($ids), "?")) . ")"; + $stmt = $db->prepare($sql); + $stmt->execute(array_merge($params, $ids)); + echo json_encode(['success' => true]); + break; + case 'bulk_update_users': $data = json_decode(file_get_contents('php://input'), true); $userIds = $data['user_ids']; diff --git a/cards.php b/cards.php index 179c650..ced6352 100644 --- a/cards.php +++ b/cards.php @@ -31,16 +31,51 @@

출입증 관리

보안실 연동 임시 출입증 및 NFC ID 관리

- + +
+
+
+ + 개 선택됨 +
+
+
+ 일괄 변경: + + + +
+
+ +
+
+ -
+ + 카드 번호 카드 종류 @@ -52,19 +87,23 @@