getConnection(); mysqli_set_charset($c, 'utf8'); // Fetch departments $dept_opts = []; $dept_q = "SELECT id, name FROM gavi_departments ORDER BY name"; $dept_r = mysqli_query($c, $dept_q); while ($row = mysqli_fetch_assoc($dept_r)) { $dept_opts[] = $row; } $users = []; $q = "SELECT cu.id, cu.name, cu.email, cu.goo, cud.department_id FROM conf_users cu LEFT JOIN conf_user_departments cud ON cud.user_id = cu.id ORDER BY cu.name"; $r = mysqli_query($c, $q); while ($row = mysqli_fetch_assoc($r)) { $users[] = $row; } // Handle AJAX updates if ($_SERVER['REQUEST_METHOD'] === 'POST') { $uid = isset($_POST['id']) ? intval($_POST['id']) : 0; $field = isset($_POST['field']) ? $_POST['field'] : ''; $value = isset($_POST['value']) ? trim($_POST['value']) : ''; if ($uid > 0 && in_array($field, ['name','email','goo'])) { $stmt = mysqli_prepare($c, "UPDATE conf_users SET $field = ? WHERE id = ?"); mysqli_stmt_bind_param($stmt, "si", $value, $uid); mysqli_stmt_execute($stmt); echo json_encode(['ok' => true]); exit; } if ($uid > 0 && $field === 'department_id') { $dept = intval($value); if ($dept > 0) { $stmt = mysqli_prepare($c, "INSERT INTO conf_user_departments (user_id, department_id) VALUES (?, ?) ON DUPLICATE KEY UPDATE department_id = VALUES(department_id)"); mysqli_stmt_bind_param($stmt, "ii", $uid, $dept); mysqli_stmt_execute($stmt); } else { $stmt = mysqli_prepare($c, "DELETE FROM conf_user_departments WHERE user_id = ?"); mysqli_stmt_bind_param($stmt, "i", $uid); mysqli_stmt_execute($stmt); } echo json_encode(['ok' => true]); exit; } echo json_encode(['ok' => false, 'err' => 'invalid']); exit; } $MY_TITLE = "All Users"; $MY_CRUMB = "All Users"; ob_start(); ?>
Name Email GOO Department