n

이미지 경로를 도메인으로 조절하는 예시 소스.

각종 프레임워크를 활용해 만든 예시 페이지입니다.

 

[code]<?php

require_once 'admin_header.php';

require_once '../db_config.php';

 

ini_set('display_errors', 1);

ini_set('display_startup_errors', 1);

error_reporting(E_ALL);

 

// 이미지 경로 수정 함수

function correctImagePath($path) {

    // URL 파싱

    $parsed_url = parse_url($path);

   

    // 도메인 추출 (스키마 포함)

    $domain = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' . $parsed_url['host'] : 'https://seohai.kr';

   

    // 파일명 추출

    $filename = basename($path);

   

    // 새로운 경로 생성

    return $domain . '/uploads/img/' . $filename;

}

 

try {

    $pdo = connectDB();

 

    // 페이지네이션 설정

    $page = isset($_GET['page']) ? (int)$_GET['page'] : 1;

    $perPage = 10;

    $start = ($page - 1) * $perPage;

 

    // 전체 문의 수 가져오기

    $stmt = $pdo->query("SELECT COUNT(*) FROM dqna");

    $total = $stmt->fetchColumn();

 

    // 문의 목록 가져오기 (이미지 정보 포함)

    $stmt = $pdo->prepare("

        SELECT d.*, u.username, GROUP_CONCAT(di.image_path) as image_paths

        FROM dqna d

        JOIN users u ON d.user_id = u.id

        LEFT JOIN dqna_images di ON d.id = di.dqna_id

        GROUP BY d.id

        ORDER BY d.created_at DESC

        LIMIT :start, :perPage

    ");

    $stmt->bindParam(':start', $start, PDO::PARAM_INT);

    $stmt->bindParam(':perPage', $perPage, PDO::PARAM_INT);

    $stmt->execute();

    $inquiries = $stmt->fetchAll(PDO::FETCH_ASSOC);

 

    // 답변 제출 처리

    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'reply') {

        $inquiry_id = $_POST['inquiry_id'];

        $admin_reply = $_POST['admin_reply'];

 

        $stmt = $pdo->prepare("UPDATE dqna SET admin_reply = ?, admin_reply_at = NOW(), status = 'answered' WHERE id = ?");

        $stmt->execute([$admin_reply, $inquiry_id]);

 

        $success_message = "답변이 성공적으로 제출되었습니다.";

    }

} catch (PDOException $e) {

    die("데이터베이스 오류: " . $e->getMessage());

}

?>

 

<!DOCTYPE html>

<html lang="ko">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>1:1 문의 관리 - </title>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">

</head>

<body>

    <div class="container mt-4">

        <h2>1:1 문의 관리</h2>

 

        <?php if (isset($success_message)): ?>

            <div class="alert alert-success" role="alert">

                <?php echo $success_message; ?>

            </div>

        <?php endif; ?>

 

        <?php if (empty($inquiries)): ?>

            <p>현재 문의가 없습니다.</p>

        <?php else: ?>

            <table class="table table-striped">

                <thead>

                    <tr>

                        <th>ID</th>

                        <th>사용자</th>

                        <th>제목</th>

                        <th>상태</th>

                        <th>작성일</th>

                        <th>액션</th>

                    </tr>

                </thead>

                <tbody>

                    <?php foreach ($inquiries as $inquiry): ?>

                        <tr>

                            <td><?php echo $inquiry['id']; ?></td>

                            <td><?php echo htmlspecialchars($inquiry['username']); ?></td>

                            <td><?php echo htmlspecialchars($inquiry['title']); ?></td>

                            <td><?php echo $inquiry['status'] === 'pending' ? '대기중' : '답변완료'; ?></td>

                            <td><?php echo $inquiry['created_at']; ?></td>

                            <td>

                                <button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#inquiryModal<?php echo $inquiry['id']; ?>">

                                    상세보기/답변

                                </button>

                            </td>

                        </tr>

                    <?php endforeach; ?>

                </tbody>

            </table>

 

            <!-- 페이지네이션 -->

            <nav aria-label="Page navigation">

                <ul class="pagination">

                    <?php

                    $totalPages = ceil($total / $perPage);

                    for ($i = 1; $i <= $totalPages; $i++):

                    ?>

                        <li class="page-item <?php echo $i === $page ? 'active' : ''; ?>">

                            <a class="page-link" href="?page=<?php echo $i; ?>"><?php echo $i; ?></a>

                        </li>

                    <?php endfor; ?>

                </ul>

            </nav>

 

            <!-- 모달 -->

            <?php foreach ($inquiries as $inquiry): ?>

                <div class="modal fade" id="inquiryModal<?php echo $inquiry['id']; ?>" tabindex="-1" aria-labelledby="inquiryModalLabel<?php echo $inquiry['id']; ?>" aria-hidden="true">

                    <div class="modal-dialog modal-lg">

                        <div class="modal-content">

                            <div class="modal-header">

                                <h5 class="modal-title" id="inquiryModalLabel<?php echo $inquiry['id']; ?>">문의 상세 정보</h5>

                                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>

                            </div>

                            <div class="modal-body">

                                <h6>제목: <?php echo htmlspecialchars($inquiry['title']); ?></h6>

                                <p><strong>내용:</strong> <?php echo nl2br(htmlspecialchars($inquiry['content'])); ?></p>

                                <p><strong>작성자:</strong> <?php echo htmlspecialchars($inquiry['username']); ?></p>

                                <p><strong>작성일:</strong> <?php echo $inquiry['created_at']; ?></p>

                               

                                <?php if (!empty($inquiry['image_paths'])): ?>

                                    <h6>첨부 이미지:</h6>

                                    <div class="row">

                                        <?php foreach (explode(',', $inquiry['image_paths']) as $image_path): ?>

                                            <div class="col-md-4 mb-3">

                                                <img src="<?php echo htmlspecialchars(correctImagePath($image_path)); ?>" class="img-fluid" alt="첨부 이미지">

                                            </div>

                                        <?php endforeach; ?>

                                    </div>

                                <?php endif; ?>

                               

                                <?php if ($inquiry['status'] === 'answered'): ?>

                                    <hr>

                                    <h6>관리자 답변:</h6>

                                    <p><?php echo nl2br(htmlspecialchars($inquiry['admin_reply'])); ?></p>

                                    <p><strong>답변일:</strong> <?php echo $inquiry['admin_reply_at']; ?></p>

                                <?php endif; ?>

 

                                <hr>

                                <h6>답변 작성</h6>

                                <form action="inquiries.php" method="post">

                                    <input type="hidden" name="action" value="reply">

                                    <input type="hidden" name="inquiry_id" value="<?php echo $inquiry['id']; ?>">

                                    <div class="mb-3">

                                        <textarea class="form-control" name="admin_reply" rows="5" required><?php echo htmlspecialchars($inquiry['admin_reply'] ?? ''); ?></textarea>

                                    </div>

                                    <button type="submit" class="btn btn-primary">답변 제출</button>

                                </form>

                            </div>

                        </div>

                    </div>

                </div>

            <?php endforeach; ?>

        <?php endif; ?>

    </div>

 

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>

</body>

</html>

 

<?php require_once 'admin_footer.php'; ?>[/code]

 

|

댓글 1개

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기
🐛 버그신고