From e333930c09af42fec73584cb235fed627095be0c Mon Sep 17 00:00:00 2001 From: NAS-Admin Date: Sun, 8 Feb 2026 21:28:22 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B0=98=EC=98=81=EB=B3=B4=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.php | 33 ++++++++++++++++++------ departments.php | 23 +++++++++++++---- users.php | 67 ++++++++++++++++++++++++++++++++++++------------- 3 files changed, 93 insertions(+), 30 deletions(-) diff --git a/api.php b/api.php index 343de55..0030d8d 100644 --- a/api.php +++ b/api.php @@ -387,7 +387,7 @@ try { echo json_encode(['success' => true, 'merged' => true]); } else { // Check if a department with the same name exists under the same parent (excluding itself) - $check_stmt = $db->prepare("SELECT id FROM departments WHERE name = ? AND (parent_id <=> ?) AND id != ?"); + $check_stmt = $db->prepare("SELECT id FROM departments WHERE name = ? AND parent_id IS ? AND id != ?"); $check_stmt->execute([$new_name, $parent_id, $dept_id]); $existing = $check_stmt->fetch(); @@ -403,18 +403,32 @@ try { case 'delete_dept': $dept_id = $_GET['id']; - // 1. Find the '미소속' department ID - $miso_id = $db->query("SELECT id FROM departments WHERE name = '미소속'")->fetchColumn(); + + // Find FKI Root + $fki_root = $db->query("SELECT id FROM departments WHERE name = '한국경제인협회' AND parent_id IS NULL LIMIT 1")->fetch(); + $fki_root_id = $fki_root ? $fki_root['id'] : null; + + // 1. Find the '미소속' department under FKI Root + $miso_id = $db->query("SELECT id FROM departments WHERE name = '미소속' AND parent_id IS " . ($fki_root_id ?: 'NULL') . " LIMIT 1")->fetchColumn(); + if (!$miso_id) { - // Fallback creation if not exists - $db->exec("INSERT INTO departments (name, level) VALUES ('미소속', 0)"); + $db->prepare("INSERT INTO departments (name, parent_id, level) VALUES ('미소속', ?, 1)")->execute([$fki_root_id]); $miso_id = $db->lastInsertId(); } - // 2. Move members to '미소속' + // 2. Get current dept info for re-parenting children + $current_dept = $db->prepare("SELECT parent_id FROM departments WHERE id = ?"); + $current_dept->execute([$dept_id]); + $parent_info = $current_dept->fetch(); + $target_new_parent = $parent_info ? $parent_info['parent_id'] : null; + + // 3. Move members to '미소속' $db->prepare("UPDATE users SET department_id = ? WHERE department_id = ?")->execute([$miso_id, $dept_id]); - // 3. Delete the department + // 4. Move child departments to its grandparent (re-parenting) to avoid FK constraint violation + $db->prepare("UPDATE departments SET parent_id = ? WHERE parent_id = ?")->execute([$target_new_parent, $dept_id]); + + // 5. Delete the department $db->prepare("DELETE FROM departments WHERE id = ?")->execute([$dept_id]); echo json_encode(['success' => true]); @@ -582,6 +596,11 @@ try { $updates[] = "department_id = ?"; $params[] = $newDeptId; } + $newPosition = $data['position'] ?? null; + if ($newPosition) { + $updates[] = "position = ?"; + $params[] = $newPosition; + } if (empty($updates)) { echo json_encode(['success' => false, 'error' => 'No updates specified']); diff --git a/departments.php b/departments.php index 2ac6cdf..00d840d 100644 --- a/departments.php +++ b/departments.php @@ -88,10 +88,6 @@

-
@@ -115,6 +111,13 @@
+
+ +

※ 삭제 시 소속 인원은 '미소속'으로 이동됩니다.

+
@@ -245,12 +248,22 @@ deleteDept() { if (confirm(`정말로 '${this.formData.name}' 부서를 제거하시겠습니까?\n이 명령을 수행하면 소속된 부서원들은 자동으로 '[한국경제인협회] - 미소속' 부서로 이동됩니다.\n이 작업은 되돌릴 수 없습니다.`)) { fetch(`api.php?action=delete_dept&id=${this.formData.id}`) - .then(res => res.json()) + .then(res => { + if (!res.ok) throw new Error('네트워크 응답이 올바르지 않습니다.'); + return res.json(); + }) .then(data => { if (data.success) { + alert('부서가 성공적으로 제거되었습니다.'); this.showModal = false; this.fetchDepts(); + } else { + alert('부서 제거 중 오류가 발생했습니다: ' + (data.error || '알 수 없는 오류')); } + }) + .catch(err => { + console.error(err); + alert('부서 제거 요청 중 오류가 발생했습니다.'); }); } }, diff --git a/users.php b/users.php index 0477dc7..a6a83cf 100644 --- a/users.php +++ b/users.php @@ -102,7 +102,8 @@
-
+
Selected 인원 선택됨 @@ -116,6 +117,7 @@ + + - +
@@ -160,8 +167,8 @@ x-text="sortOrder === 'asc' ? '↑' : '↓'">
- 연락처 - + 연락처 / + 사내전화
@@ -206,7 +213,16 @@
-
+
+
+ Mobile + +
+
+ 사내전화 + +
+
휴직 + @@ -285,13 +305,6 @@
-
- - -
-
-
+
+
+
+ + +
+
+ + +
+
+
@@ -337,7 +365,8 @@ selectedIds: [], bulkStatus: '', bulkDeptId: '', - formData: { id: '', name: '', emp_id: '', department_id: '', position: '', email: '', mobile: '', accounting_type: '일반회계', status: 'active' }, + bulkPosition: '', + formData: { id: '', name: '', emp_id: '', department_id: '', position: '', email: '', mobile: '', accounting_type: '일반회계', status: 'active', phone: '' }, init() { this.fetchUsers(); @@ -355,7 +384,7 @@ result = result.filter(u => u.name.toLowerCase().includes(q) || u.emp_id.toLowerCase().includes(q) || (u.email && u.email.toLowerCase().includes(q))); } if (!this.filterRetired) result = result.filter(u => u.status !== 'retired'); - if (!this.filterOnLeave) result = result.filter(u => u.status !== 'on_leave'); + if (!this.filterOnLeave) result = result.filter(u => u.status !== 'on_leave' && u.status !== 'classification'); if (this.sortKey) { result.sort((a, b) => { @@ -426,20 +455,22 @@ }, applyBulkUpdate() { - if (!this.bulkStatus && !this.bulkDeptId) return; + if (this.selectedIds.length === 0) return; fetch('api.php?action=bulk_update_users', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ user_ids: this.selectedIds, status: this.bulkStatus, - department_id: this.bulkDeptId + department_id: this.bulkDeptId, + position: this.bulkPosition }) }).then(res => res.json()).then(data => { if (data.success) { this.selectedIds = []; this.bulkStatus = ''; this.bulkDeptId = ''; + this.bulkPosition = ''; this.fetchUsers(); } });