<?php
$usr_level = session('usr_level');

$regi_pdf_path = "";
if (!empty($list['cert_register']) && $list['cert_register_save_yn'] != 'Y') {	//등기url있고 등기api이미지 저장여부가 Y가 아닐때 
    $arr_cert_register = explode('|', $list['cert_register']);
    $file_pdf = substr($list['cert_register'], -4);
    $file_pdf = str_replace(".", "", $file_pdf);

    $regi_pdf_path = $list['cert_register'];
} else {
    if (!empty($regist)) {
        $file_pdf = substr($regist['file_name'], -3);
        $regi_pdf_path = $regist['file_path'] . $regist['file_name'];
    }
}
?>

<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>
<style>
    .tbl_basic2 th {
        padding: 0 10px;
        height: 27px;
        border: solid 1px #d8d9de;
        background-color: #eff0f4;
        letter-spacing: -1px;
        font-weight: normal;
        color: #5a5f69;
        text-align: left;
        vertical-align: middle;
    }

    .blockUI {
        z-index: 1500 !important;
    }

    .ellipsis {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 180px;
    }

    .card-header {
        display: flex !important;
        align-items: center;
    }

    .card-header-tab {
        justify-content: flex-start !important;
    }

    .table-scroll {
        max-height: 300px;
        overflow-y: scroll;
    }

    .swal2-cancel {
        background-color: #ff0000 !important;
        color: #fff !important;
    }

    .num {
        color: #b68556;
        font-size: 19px;
    }

    .table th,
    .table td {
        vertical-align: top;
        box-sizing: border-box;
    }
</style>

<div class="app-page-title">
    <div class="page-title-wrapper">
        <div class="page-title-heading">
            <div>1차 재검증 매물상세</div>
        </div>
    </div>
</div>

<div class="col-md-12 col-xl-12">
    <div class="col-lg-12">
        <div class="main-card mb-3 card">
            <div class="card-header" style="width:100%; max-width:100%; min-width:600px; padding:0; border:0;">
                <p class="left">
                </p>
                <table style="width:100%; min-width:600px; padding:0; border:0;" cellpadding="0" cellspacing="0"
                    border="0" width="100%">
                    <tbody>
                        <tr>
                            <td style="width: 50%;padding-left: 20px"><span class="tit">매물ID :</span> <span
                                    class="num"><?= $data['atcl_no'] ?></span>
                            </td>
                            <td style="width: 20%;"><span class="tit">CP ID :</span> <span
                                    class="num"><?= $data['cpid'] ?></span></td>
                            <td style="width: 30%; text-align: right;padding-right: 20px"><span class="tit">현재 상태
                                    :</span> <span class="num"><?= $data['pre_stat'] ?></span></td>
                        </tr>
                        <tr>
                            <td height="15"></td>
                            <td></td>
                            <td></td>
                        </tr>
                    </tbody>
                </table>
                <p></p>
            </div>
            <div class="card-body">
                <h5 class="card-title">공인 중개사 정보</h5>
                <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
                    <colgroup>
                        <col width="15%" />
                        <col width="35%" />
                        <col width="15%" />
                        <col width="35%" />
                    </colgroup>
                    <tr>
                        <th>중개사명</th>
                        <td><?= $data['realtor_nm'] ?></td>
                        <th>대표전화</th>
                        <td><?= $data['realtor_tel_no'] ?></td>
                    </tr>

                </table>
            </div>
        </div>

        <!-- 매물정보 -->
        <div class="main-card mb-3 card">
            <div class="card-body">
                <h5 class="card-title">매물 정보</h5>
                <div class="table-responsive">
                    <table class="table table-bordered table-sm align-middle tbl_basic2">
                        <colgroup>
                            <col style="width:120px">
                            <col style="width:320px">
                            <col style="width:120px">
                            <col style="width:320px">
                        </colgroup>

                        <tbody>
                            <tr>
                                <th>등록일</th>
                                <td>
                                    <?= $data['rdate'] ?>
                                </td>

                                <th>전화/서류 완료일시</th>
                                <td>
                                    <select class="form-select form-select-sm" name="atcl_vrtc_way" id="atcl_vrtc_way"
                                        disabled>
                                        <option value="">-선택-</option>
                                        <?php foreach ($codes as $c): ?>
                                            <?php if ($c['category'] === "VRFCREQ_WAY"): ?>
                                                <option value="<?= $c['cd'] ?>" <?= ($c['cd'] === $data['vrfc_type_cd']) ? 'selected' : '' ?>>
                                                    <?= $c['cd_nm'] ?>
                                                </option>
                                            <?php endif; ?>
                                        <?php endforeach; ?>
                                    </select>
                                    <?= $data['update_res_tm'] ?>
                                </td>
                            </tr>
                            <tr>
                                <th>등기부등본 확인완료</th>
                                <td>
                                    <?= $data['result_tm'] ?>
                                </td>

                                <th>의뢰인(매도자)</th>
                                <td>
                                    <?php if (in_array($data['stat_cd'], ['19', '60', '69'])): ?>
                                        ***
                                    <?php else: ?>
                                        <?= $data['seller_nm'] ?>
                                    <?php endif; ?>
                                </td>
                            </tr>

                            <tr>
                                <th>매물구분</th>
                                <td>
                                    <?= $data['atcl_nm'] ?>
                                </td>

                                <th>거래구분</th>
                                <td>
                                    <div class="d-flex flex-wrap gap-3">
                                        <div class="form-check">
                                            <input class="form-check-input" type="radio" name="trade_type_cd"
                                                id="trade_type_1" value="B1" <?= ($data['trade_type_cd'] === 'B1') ? 'checked' : '' ?> disabled>
                                            <label class="form-check-label" for="trade_type_1">전세</label>
                                        </div>

                                        <div class="form-check">
                                            <input class="form-check-input" type="radio" name="trade_type_cd"
                                                id="trade_type_2" value="B2" <?= ($data['trade_type_cd'] === 'B2') ? 'checked' : '' ?> disabled>
                                            <label class="form-check-label" for="trade_type_2">월세</label>
                                        </div>

                                        <div class="form-check">
                                            <input class="form-check-input" type="radio" name="trade_type_cd"
                                                id="trade_type_4" value="B3" <?= ($data['trade_type_cd'] === 'B3') ? 'checked' : '' ?> disabled>
                                            <label class="form-check-label" for="trade_type_4">단기임대</label>
                                        </div>

                                        <div class="form-check">
                                            <input class="form-check-input" type="radio" name="trade_type_cd"
                                                id="trade_type_3" value="A1" <?= ($data['trade_type_cd'] === 'A1') ? 'checked' : '' ?> disabled>
                                            <label class="form-check-label" for="trade_type_3">매매</label>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                            <tr>
                                <th rowspan="3">지역구분</th>
                                <td rowspan="3">
                                    <?= $data['region_nm'] ?>
                                </td>

                                <th>리 주소</th>
                                <td>
                                    <input type="text" class="form-control form-control-sm"
                                        value="<?= $data['address2a'] ?>" disabled>
                                </td>
                            </tr>

                            <tr>
                                <th>상세주소</th>
                                <td class="d-flex gap-1">
                                    <?php if (empty($data['address2b'])): ?>
                                        <input type="text" class="form-control form-control-sm"
                                            value="<?= $data['address2'] ?>" disabled>
                                        <input type="hidden" name="atcl_addr1b" id="atcl_addr1b" value=" ">
                                    <?php else: ?>
                                        <input type="hidden" name="atcl_addr1" id="atcl_addr1" value=" ">
                                        <input type="text" class="form-control form-control-sm"
                                            value="<?= $data['address2b'] ?>" disabled>
                                    <?php endif; ?>

                                    <input type="text" class="form-control form-control-sm"
                                        value="<?= $data['address3'] ?>" disabled>
                                </td>
                            </tr>

                            <tr>
                                <th>기타주소</th>
                                <td>
                                    <input type="text" class="form-control form-control-sm"
                                        value="<?= $data['address4'] ?>" disabled>
                                </td>
                            </tr>

                            <tr>
                                <th>단지명</th>
                                <td>
                                    <input type="hidden" name="atcl_hscp_nm" id="atcl_hscp_nm"
                                        value="<?= $data['hscp_nm'] ?>" />
                                    <?php
                                    /*
                                    $js = 'id="atcl_hscp_no" onchange="ajax_code_ptpList(this.value)" disabled="disabled"';
                                    echo form_dropdown('atcl_hscp_no', $complexList, $data['hscp_no'], $js);
                                    */
                                    ?>
                                </td>

                                <th>가격</th>
                                <td>
                                    <!-- 기본 가격 -->
                                    <div class="align-items-center gap-2 mb-2" id="div_trade_type_price"
                                        style="display: none;">
                                        <div class="input-group input-group-sm" style="max-width: 220px;">
                                            <input type="text" class="form-control text-end" name="atcl_amt1"
                                                id="atcl_amt1" value="<?= $data['deal_amt'] ?>" disabled>
                                            <span class="input-group-text">만원</span>
                                        </div>

                                        <?php if (in_array($usr_level, [1, 2])): ?>
                                            <div class="form-check d-flex align-items-center mb-0">
                                                <input class="form-check-input mt-0" type="checkbox" id="price_ignore1"
                                                    disabled>
                                                <label class="form-check-label ms-1 small" for="price_ignore1">
                                                    가격무시
                                                </label>
                                            </div>
                                        <?php endif; ?>
                                    </div>

                                    <div class="align-items-center gap-1 mb-2" id="div_trade_type_price_monthly"
                                        style="display: none;">
                                        <div class="input-group input-group-sm" style="max-width: 220px;">
                                            <input type="text" class="form-control text-end" name="atcl_amt2"
                                                id="atcl_amt2" value="<?= $data['wrrnt_amt'] ?>" disabled>
                                        </div> /
                                        <div class="input-group input-group-sm" style="max-width: 220px;">
                                            <input type="text" class="form-control text-end" name="atcl_amt3"
                                                id="atcl_amt3" value="<?= $data['lease_amt'] ?>" disabled>
                                            <span class="input-group-text">만원</span>
                                        </div>


                                        <?php if (in_array($usr_level, [1, 2])): ?>
                                            <div class="form-check d-flex align-items-center mb-0">
                                                <input class="form-check-input mt-0" type="checkbox" id="price_ignore2"
                                                    disabled>
                                                <label class="form-check-label ms-1 small" for="price_ignore2">
                                                    가격무시
                                                </label>
                                            </div>
                                        <?php endif; ?>
                                    </div>

                                    <!-- 분양가 / 프리미엄 -->
                                    <div id="div_trade_type_price2" style="display: none;">

                                        <div class="align-items-center gap-2 mb-2">
                                            <div class="input-group input-group-sm" style="max-width: 220px;">
                                                <input type="text" class="form-control text-end" name="atcl_amt4"
                                                    id="atcl_amt4" value="<?= $data['deal_amt'] ?>" disabled>
                                                <span class="input-group-text">만원</span>
                                            </div>

                                            <?php if (in_array($usr_level, [1, 2])): ?>
                                                <div class="form-check d-flex align-items-center mb-0">
                                                    <input class="form-check-input mt-0" type="checkbox" id="price_ignore1"
                                                        disabled>
                                                    <label class="form-check-label ms-1 small" for="price_ignore1">
                                                        가격무시
                                                    </label>
                                                </div>
                                            <?php endif; ?>



                                            <div class="row g-2 align-items-center">
                                                <div class="col-md-6">
                                                    <label class="form-label small mb-1 text-muted">분양가</label>
                                                    <div class="input-group input-group-sm">
                                                        <input type="text" class="form-control text-end"
                                                            name="isale_amt" id="isale_amt"
                                                            value="<?= str_replace(',', '', $data['isale_amt']) ?>"
                                                            disabled>
                                                        <span class="input-group-text">만원</span>
                                                    </div>
                                                </div>

                                                <div class="col-md-6">
                                                    <label class="form-label small mb-1 text-muted">프리미엄</label>
                                                    <div class="input-group input-group-sm">
                                                        <input type="text" class="form-control text-end" name="prem_amt"
                                                            id="prem_amt"
                                                            value="<?= str_replace(',', '', $data['prem_amt']) ?>"
                                                            disabled>
                                                        <span class="input-group-text">만원</span>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </td>
                            </tr>

                            <tr>
                                <th>평형</th>
                                <td>
                                    <input type="hidden" name="atcl_ptp_nm" id="atcl_ptp_nm" value="">
                                    <select class="form-select form-select-sm" name="atcl_ptp_no" id="atcl_ptp_no"
                                        disabled>
                                        <option value="">-평형-</option>
                                    </select>
                                </td>

                                <th>층 / 총층</th>
                                <td>
                                    <div class="d-flex align-items-center gap-2">
                                        <input type="text" class="form-control form-control-sm" style="max-width:80px;"
                                            name="atcl_floor" id="atcl_floor" value="<?= $data['floor'] ?>" disabled>
                                        <span class="text-muted">/</span>
                                        <input type="text" class="form-control form-control-sm" style="max-width:80px;"
                                            name="atcl_floor2" id="atcl_floor2" value="<?= $data['floor2'] ?>" disabled>
                                    </div>
                                </td>
                            </tr>

                            <?php if ($data['dong_ho_chk'] == 'N' && $data['hscplqry_lv'] == '3'): ?>
                                <tr>
                                    <th>공급면적</th>
                                    <td>
                                        <span style="color:#F21E1E">
                                            <?= $list['sply_spc'] ?>
                                        </span>
                                    </td>
                                    <th>전용면적</th>
                                    <td>
                                        <span style="color:#F21E1E">
                                            <?= $list['excls_spc'] ?>
                                        </span>
                                    </td>
                                </tr>
                            <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            <?php if (intval($data['stat_cd']) < 45 && intval($data['stat_cd']) != 39):
                if (intval($data['try_cnt'] ?? 0) < 2):
                    ?>
                    <div class="card-footer d-flex justify-content-end gap-1">
                        <button class="mb-2 me-2 btn-transition btn btn-outline-secondary" id="priceModify"
                            style="display: none;">가격수정</button>
                        <button class="mb-2 me-2 btn-transition btn btn-outline-secondary" id="btnModify">수정</button>
                        <button class="mb-2 me-2 btn btn-primary" id="btnSave" disabled>저장</button>
                    </div>

                <?php endif;
            endif; ?>
        </div>

        <!-- 서류확인정보 -->
        <div class="main-card mb-3 card" id="docu_chk" style="display: none;">
            <div class="card-body">
                <h5 class="card-title">서류확인 정보</h5>

                <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
                    <colgroup>
                        <col width="60%">
                        <col>
                    </colgroup>

                    <tbody>
                        <tr>
                            <!-- 좌측 : 이미지 -->
                            <td>
                                <div id="douc_img_dis" class="py-2">
                                    <?php if (!empty($data['confirm_doc_img_url'])): ?>

                                        <?php if ($data['confirm_doc_img_url_save_yn'] == 'Y'):
                                            $img_path = $record['file_path'] . $record['file_name'];
                                            $ext = $record['file_ext'];

                                            if (strtolower($ext) == '.pdf'):
                                                ?>
                                                <iframe src="<?= $server_addr ?><?= $img_path ?>" frameborder="0"
                                                    style="padding: 10px 0;width:100%; height:800px;"></iframe><br>
                                            <?php elseif (!in_array($ext, ['.zip', '.ZIP', '.pdf', '.PDF'])): ?>
                                                <?php foreach ($arrRecord as $row):
                                                    $arr_img_path = $row['file_path'] . $row['file_name'];
                                                    ?>
                                                    <a href="<?= $arr_img_path ?>">
                                                        <?php if (strcmp($img_path, $arr_img_path) == 0): ?>
                                                            <img id="photo-display" src="<?= $img_path ?>" alt="Image"
                                                                style="width:100%;max-width:945px;min-width:100%;border:0;" />
                                                        <?php endif; ?>
                                                    </a>
                                                <?php endforeach; ?>
                                            <?php endif; ?>

                                        <?php else:
                                            $img_path = $data['confirm_doc_img_url'];
                                            $ext = strrchr($data['confirm_doc_img_url'], ".");	//맨뒤에.부터 자른다    
                                    
                                            if (strtolower($ext) == '.pdf'):
                                                ?>
                                                <iframe src="<?= $img_path ?>" frameborder="0"
                                                    style="padding: 10px 0;width:100%; height:800px;"></iframe>
                                            <?php else: ?>

                                            <?php endif; ?>
                                            <img id="photo-display" src="<?= $img_path ?>" alt="Image"
                                                style="width:100%;max-width:945px;min-width:100%;border:0;" />
                                        <?php endif; ?>
                                    <?php else: ?>

                                        <a href="#" rel="lightbox[gallery]">
                                            <img id="photo-display" src="/plugin/img/photo.gif" alt="Image"
                                                style="width:100%; max-width:945px; border:0;">
                                        </a>

                                        <div id="div_fild_upload" class="text-end">

                                            <button class="btn btn-sm btn-primary">
                                                업로드
                                            </button>
                                        </div>
                                    <?php endif; ?>
                                </div>


                            </td>

                            <!-- 우측 : 정보 -->
                            <td valign="top" class="pt-2">
                                <table class="tbl_basic4 w-100">
                                    <colgroup>
                                        <col width="30%">
                                        <col>
                                    </colgroup>

                                    <tbody>
                                        <tr>
                                            <th>확인담당자</th>
                                            <td>관리자</td>
                                        </tr>

                                        <tr>
                                            <th>확인여부</th>
                                            <td>
                                                <select class="form-select" id="fax_conf_res_d11"
                                                    name="fax_conf_res_d11">
                                                    <option value="">-선택-</option>
                                                    <?php foreach ($codes as $c): ?>
                                                        <?php if ($c['category'] === "CONFIRM_RESULT_D11"): ?>
                                                            <option value="<?= $c['cd'] ?>" <?= ($c['cd'] === $data['result_d11']) ? 'selected' : '' ?>>
                                                                <?= $c['cd_nm'] ?>
                                                            </option>
                                                        <?php endif; ?>
                                                    <?php endforeach; ?>
                                                </select>
                                            </td>
                                        </tr>

                                        <tr>
                                            <th>홍보확인서<br>미확인여부상세</th>
                                            <td>
                                                <table class="w-100">
                                                    <tr>
                                                        <?php
                                                        $checks = explode('|', $data['comment']);
                                                        // if (in_array($confirm['code_d11'], ['20011', '20012'])) {
                                                        $disabled = '';
                                                        // } else {
                                                        $disabled = ' disabled="disabled"';
                                                        // }
                                                        
                                                        $attributes = [
                                                            'style' => 'font-weight:normal;',
                                                        ];

                                                        $nCnt = 0;
                                                        $code_comment = [];
                                                        foreach ($codes as $c) {
                                                            if ($c['category'] === "CONSULTANT_COMMENT") {
                                                                array_push($code_comment, $c);
                                                            }
                                                        }

                                                        foreach ($code_comment as $key => $value) {
                                                            if ($nCnt % 2 == 0 && $nCnt != 0) {
                                                                echo '</tr><tr>';
                                                            }

                                                            if (in_array($key, $checks)) {
                                                                $check = TRUE;
                                                            } else {
                                                                $check = FALSE;
                                                            }

                                                            ?>
                                                            <td style="border: 0; padding:2px 0 2px 0; height:18px;">
                                                                <div class="form-check d-flex align-items-center mb-0">
                                                                    <input class="form-check-input mt-0" type="checkbox"
                                                                        id="comment_<?= $key ?>" disabled>
                                                                    <label class="form-check-label ms-1 small"
                                                                        for="price_ignore1">
                                                                        <?= $value['cd_nm'] ?>
                                                                    </label>
                                                                </div>
                                                            </td>


                                                            <?php $nCnt++;
                                                        } ?>

                                                        <?php if ($nCnt > 0) { ?>
                                                        </tr>
                                                    <?php } ?>
                                                </table>
                                            </td>
                                        </tr>

                                        <tr>
                                            <th>확인 내용</th>
                                            <td>
                                                <select class="form-select" id="fax_conf_yn_1">
                                                    <option value="">-선택-</option>
                                                    <option value="1" <?php if ($data['success'] == '1')
                                                        echo "selected"; ?>>
                                                        전체일치</option>
                                                    <option value="2" <?php if ($data['success'] == '2')
                                                        echo "selected"; ?>>
                                                        전체불일치</option>
                                                </select>
                                            </td>
                                        </tr>

                                        <tr>
                                            <th>매물주소</th>
                                            <td class="d-flex gap-2">
                                                <select class="form-select" id="fax_conf_yn_2">
                                                    <option value="">-선택-</option>
                                                    <option value="10000" <?php if ($data['fax_conf_yn_2'] == '10000')
                                                        echo "selected"; ?>>일치</option>
                                                    <option value="20000" <?php if ($data['fax_conf_yn_2'] == '20000')
                                                        echo "selected"; ?>>불일치</option>
                                                </select>
                                                <input type="text" class="form-control" id="fax_conf_yn_info_2"
                                                    value="<?= str_replace(',', '', $data['fax_conf_yn_info_2']) ?>">
                                            </td>
                                        </tr>

                                        <tr>
                                            <th>가격 거래구분</th>
                                            <td class="d-flex gap-2">
                                                <select class="form-select" id="fax_conf_yn_3">
                                                    <option value="">-선택-</option>
                                                    <option value="10000">일치</option>
                                                    <option value="20000">불일치</option>
                                                </select>
                                                <input type="text" class="form-control" id="fax_conf_yn_info_3"
                                                    value="<?= str_replace(',', '', $data['fax_conf_yn_info_3']) ?>">
                                            </td>
                                        </tr>

                                        <tr>
                                            <th>의뢰인정보</th>
                                            <td class="d-flex gap-2">
                                                <select class="form-select" id="fax_conf_yn_4">
                                                    <option value="">-선택-</option>
                                                    <option value="10000">일치</option>
                                                    <option value="20000">불일치</option>
                                                </select>
                                                <input type="text" class="form-control" id="fax_conf_yn_info_4"
                                                    value="<?= str_replace(',', '', $data['fax_conf_yn_info_4']) ?>">
                                            </td>
                                        </tr>

                                        <tr>
                                            <th>메모</th>
                                            <td class="d-flex align-items-end gap-1">
                                                <textarea class="form-control" id="memo_fax" rows="2"
                                                    style="resize: none;"><?= $memo['memo'] ?></textarea>
                                                <button type="button" class="btn btn-sm btn-outline-secondary"
                                                    onclick="saveMemo('fax');" style="white-space: nowrap;">
                                                    저장
                                                </button>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="card-footer d-flex justify-content-end gap-1">
                <button type="button" class="btn btn-success btn-sm" onclick="saveDocu();">
                    저장
                </button>
            </div>
        </div>

        <div class="main-card mb-3 card" id="call_chk" style="display: none;">
            <div class="card-body">
                <h5 class="card-title">전화확인 정보</h5>

                <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
                    <colgroup>
                        <col width="15%" />
                        <col width="35%" />
                        <col width="15%" />
                        <col width="35%" />
                    </colgroup>
                    <tr>
                        <th>의뢰인(매도자) 전화번호</th>
                        <td>
                            <?
                            if ($data['stat_cd'] == '19' || $data['stat_cd'] == '60' || $data['stat_cd'] == '69') {
                                echo ('***');
                            } else {
                                echo ($data['seller_tel_no']);
                            }
                            ?>
                        </td>
                        <th>개인정보 제공동의</th>
                        <td>
                            <select class="form-select" name="tel_agree" id="tel_agree">
                                <option value="">-선택-</option>
                                <?php foreach ($codes as $c): ?>
                                    <?php if ($c['category'] === "CONFIRM_RESULT_T11"): ?>
                                        <option value="<?= $c['cd'] ?>" <?php if ($c['cd'] === $data['tel_agree']) {
                                              echo "selected";
                                          } ?>><?= $c['cd_nm'] ?></option>
                                    <?php endif; ?>
                                <?php endforeach; ?>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>의뢰인(매도자) 이름</th>
                        <td>
                            <?php
                            if ($data['stat_cd'] == '19' || $data['stat_cd'] == '60' || $data['stat_cd'] == '69') {
                                echo ('***');
                            } else {
                                echo ($data['seller_nm']);
                            }
                            ?>
                        </td>
                        <th>확인담당자</th>
                        <td><?= $data['usr_nm'] ?></td>

                    </tr>
                    <tr>
                        <th rowspan="5">통화내용녹취파일</th>
                        <td rowspan="5" class="align-top">

                            <!-- 기존 업로드된 파일 정보 -->
                            <?php if (!empty($tel)) { ?>
                                <div class="mb-2 small">
                                    <div class="d-flex align-items-center gap-2 flex-wrap">
                                        <a href="<?= $tel['file_url'] ?? '#' ?>" class="text-decoration-none">
                                            <i class="fa fa-file-audio-o me-1"></i><?= $tel['file_name'] ?>
                                        </a>
                                        <span class="badge bg-light text-dark"><?= $tel['file_size'] ?>kb</span>
                                        <span class="text-muted"><?= $tel['insert_tm'] ?></span>
                                    </div>
                                </div>
                            <?php } ?>

                            <!-- 파일 업로드 -->
                            <div class="d-flex align-items-center gap-2 mb-2">
                                <input class="form-control form-control-sm" id="virtualFileTextBox1" readonly="readonly"
                                    placeholder="파일을 선택하세요" style="max-width:260px;" />

                                <label class="btn btn-sm btn-outline-secondary mb-0">
                                    <i class="fa fa-upload me-1"></i> 업로드
                                    <input type="file" id="rec_file" name="rec_file" class="d-none"
                                        onchange="cfSetFile(this, 'virtualFileTextBox1');" />
                                </label>
                            </div>

                            <!-- 확인 체크 -->
                            <div class="form-check mb-0">
                                <input class="form-check-input" type="checkbox" id="chk_telv" name="chk_telv">
                                <label class="form-check-label" for="chk_telv">녹취파일 확인</label>
                            </div>

                        </td>

                        <th>확인내용</th>
                        <td>
                            <select class="form-select form-select-sm" name="tel_suc" id="tel_suc" disabled>
                                <option value="">-선택-</option>
                                <option value="1" <?= ($data['tel_suc'] == '1') ? 'selected' : '' ?>>전체일치</option>
                                <option value="2" <?= ($data['tel_suc'] == '2') ? 'selected' : '' ?>>전체불일치</option>
                            </select>
                        </td>
                    </tr>

                    <tr>
                        <th>매물주소</th>
                        <td class="d-flex gap-2">
                            <select class="form-select" name="tel_conf_yn_2" id="tel_conf_yn_2" disabled="disabled">
                                <option value="">-선택-</option>
                                <option value="10000" <?php if ($data['tel_conf_yn_2'] == '10000')
                                    echo "selected"; ?>>일치
                                </option>
                                <option value="20000" <?php if ($data['tel_conf_yn_2'] == '20000')
                                    echo "selected"; ?>>불일치
                                </option>
                            </select>
                            <input type="text" class="form-control" name="tel_conf_yn_info_2" id="tel_conf_yn_info_2"
                                value="<?= str_replace(',', '', $data['tel_conf_yn_info_2']) ?>" size="20" />
                        </td>
                    </tr>
                    <tr>
                        <th>가격 거래구분</th>
                        <td class="d-flex gap-2">
                            <select class="form-select" name="tel_conf_yn_3" id="tel_conf_yn_3" disabled="disabled">
                                <option value="">-선택-</option>
                                <option value="10000" <?php if ($data['tel_conf_yn_3'] == '10000')
                                    echo "selected"; ?>>일치
                                </option>
                                <option value="20000" <?php if ($data['tel_conf_yn_3'] == '20000')
                                    echo "selected"; ?>>불일치
                                </option>
                            </select>
                            <input type="text" class="form-control" name="tel_conf_yn_info_3" id="tel_conf_yn_info_3"
                                value="<?= str_replace(',', '', $data['tel_conf_yn_info_3']) ?>" size="20" />
                        </td>
                    </tr>
                    <tr>
                        <th>의뢰인정보</th>
                        <td class="d-flex gap-2">
                            <select class="form-select" name="tel_conf_yn_4" id="tel_conf_yn_4" disabled="disabled">
                                <option value="">-선택-</option>
                                <option value="10000" <?php if ($data['tel_conf_yn_4'] == '10000')
                                    echo "selected"; ?>>일치
                                </option>
                                <option value="20000" <?php if ($data['tel_conf_yn_4'] == '20000')
                                    echo "selected"; ?>>불일치
                                </option>
                            </select>
                            <input type="text" class="form-control" name="tel_conf_yn_info_4" id="tel_conf_yn_info_4"
                                value="<?= str_replace(',', '', $data['tel_conf_yn_info_4']) ?>" size="20" />
                        </td>
                    </tr>
                    <tr>
                        <th>전화확인 1차 실패</th>
                        <td>
                            <div class="d-flex justify-content-start gap-3">

                                <div class="form-check d-flex align-items-center mb-0">
                                    <input class="form-check-input" type="checkbox" name="tel_conf_yn_5" id="fail_chk1"
                                        value="20040" onclick="check_only_fail(this)">
                                    <label class="form-check-label ms-1" for="fail_chk1">
                                        주소정보 오기재
                                    </label>
                                </div>

                                <div class="form-check d-flex align-items-center mb-0">
                                    <input class="form-check-input" type="checkbox" name="tel_conf_yn_5" id="fail_chk2"
                                        value="20041" onclick="check_only_fail(this)">
                                    <label class="form-check-label ms-1" for="fail_chk2">
                                        동일 번호 등록제한
                                    </label>
                                </div>

                            </div>
                        </td>
                    </tr>

                    <tr>
                        <th>메모</th>
                        <td>
                            <div class="d-flex flex-column gap-1" style="">
                                <textarea class="form-control" name="memo_tel" id="memo_tel" rows="2"
                                    style="resize: none;"><?= $memo['memo'] ?></textarea>

                                <div class="text-end">
                                    <button type="button" class="btn btn-sm btn-light" onclick="saveMemo('tel');">
                                        저장
                                    </button>
                                </div>
                            </div>
                        </td>
                        <th>통화실패사유</th>
                        <td class="d-flex gap-2">
                            <select class="form-select" name="tel_fail_cause" id="tel_fail_cause">
                                <?php foreach ($codes as $c): ?>
                                    <?php if ($c['category'] === "TEL_FAIL_CAUSE"): ?>
                                        <option value="<?= $c['cd'] ?>" <?php if ($c['cd'] === $data['tel_fail_cause']) {
                                              echo 'selected';
                                          } ?>><?= $c['cd_nm'] ?></option>
                                    <?php endif; ?>
                                <?php endforeach; ?>

                            </select>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="card-footer d-flex justify-content-end">
                <?php
                if ($usr_level == '1') {
                    ?>
                    <button class="btn btn-sm btn-light" style="white-space: nowrap;" onclick="saveTel();">
                        저장
                    </button>
                    <?php
                }
                ?>
            </div>
        </div>

        <!-- 등기부등본 정보 -->
        <div class="main-card mb-3 card" id="regibox">
            <div class="card-body">
                <h5 class="card-title">등기부등본확인 정보</h5>

                <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
                    <colgroup>
                        <col width="60%">
                        <col>
                    </colgroup>

                    <tbody>
                        <tr>
                            <!-- 좌측 : 이미지 -->
                            <td>
                                <?php if (!empty($data['cert_register'])): ?>
                                    <?php if ($data['cert_register_save_yn'] == 'Y'): ?>
                                        <?php if (strtolower($file_pdf) == 'pdf') { ?>
                                            <iframe src="<?= $server_addr ?><?= $regi_pdf_path ?>" frameborder="0"
                                                style="padding: 10px 0;width:100%; height:800px;"></iframe><br />
                                        <?php } else { ?>
                                            <div id="regi_file_dis" style="padding: 10px 0px; height: 730px; overflow-y: auto;">
                                                <?php if (empty($arrRegist)) { ?>
                                                    <img id="photo-display2" src="/img/photo.gif" alt="Image"
                                                        style="width:100%;max-width:945px;min-width:100%;border:0;" />
                                                <?php } else {
                                                    foreach ($arrRegist as $row) {
                                                        $img_path = $row['file_path'] . $row['file_name']; ?>
                                                        <a href="<?= $img_path ?>" class="default_val" target="_blank"
                                                            rel="lightbox[gallery1]">
                                                            <img id="photo-display2" src="'.$img_path.'" alt="Image"
                                                                style="width:100%;max-width:945px;min-width:100%;border:0;" />
                                                        </a>
                                                    <?php }
                                                } ?>
                                            </div><br />
                                        <?php } ?>
                                    <?php else: ?>
                                        <?php if (strtolower($file_pdf) == 'pdf') { ?>
                                            <iframe src="<?= $regi_pdf_path ?>" frameborder="0"
                                                style="padding: 10px 0;width:100%; height:800px;"></iframe><br>
                                        <?php } else { ?>
                                            <div id="regi_file_dis" style="padding: 10px 0px; height: 730px; overflow-y: auto;">
                                                <?php if (empty($arr_cert_register)) { ?>
                                                    <img id="photo-display2" src="/plugin/img/photo.gif" alt="Image"
                                                        style="width:100%;max-width:945px;min-width:100%;border:0;" />
                                                <?php } else {
                                                    foreach ($arr_cert_register as $img_path) { ?>
                                                        <a href="<?= $img_path ?>" class="default_val" target="_blank"
                                                            rel="lightbox[gallery1]">
                                                            <img id="photo-display2" src="'.$img_path.'" alt="Image"
                                                                style="width:100%;max-width:945px;min-width:100%;border:0;" />
                                                        </a>
                                                    <?php }
                                                } ?>
                                            </div><br />
                                        <?php } ?>
                                    <?php endif; ?>

                                <?php else: ?>
                                    <?php if (empty($regist)) {
                                        $regi_img_path = '/plugin/img/photo.gif';
                                    } else {
                                        if (empty($regist['file_path']) || empty($regist['file_name'])) {
                                            $regi_img_path = '/plugin/img/photo.gif';
                                        } else {
                                            $regi_img_path = $regist['file_path'] . $regist['file_name'];

                                            if ($regist['cloud_upload_yn'] === "Y") {
                                                $regi_img_path = NCLOUD_OBJECT_STORAGE_URL . $regi_img_path;
                                            }
                                        }

                                    }
                                    ?>

                                    <div id="regi_file_dis" style="padding: 10px 0;">
                                        <img id="photo-display2" src="<?= $regi_img_path ?>" alt="Image"
                                            style="width:100%;max-width:945px;min-width:100%;border:0;" />
                                    </div>
                                    <div id="regi_file_pdf" style="padding: 10px 0; display:none;">
                                        <a href="<?= $regi_pdf_path ?>" class="embed"></a>
                                    </div>

                                <?php endif; ?>
                            </td>

                            <!-- 우측 : 정보 -->
                            <td valign="top" class="pt-2">
                                <table class="tbl_basic4 w-100">
                                    <colgroup>
                                        <col width="30%">
                                        <col>
                                    </colgroup>

                                    <tbody>
                                        <tr>
                                            <th>확인담당자</th>
                                            <td>
                                                <?= $data['reg_charger_nm'] ?>

                                                <input type="button" class="btn btn-sm btn-outline-light"
                                                    name="btnSilver" value="등기부등본 열람"
                                                    onClick="window.open('https://www.realtop.co.kr/cm/CMMBR01C2.asp2?cmInstCd=Z265&cmUserNo=<?= session('usr_id') ?>&cmKey=nxfT5VLGXg&cmName=<?= session('usr_id') ?>&cmDNm=confirms&cmAutoLogInYn=Y&cmUrl=/re/NVRET01R0&cmEncoding=UTF-8')">
                                            </td>
                                        </tr>

                                        <tr>
                                            <th>확인내용</th>
                                            <td>
                                                <select class="form-select" id="reg_conf_yn_1" name="reg_conf_yn_1">
                                                    <option value="">-선택-</option>
                                                    <option value="1" <?php if ($data['reg_conf_yn_1'] == '1')
                                                        echo "selected"; ?>>전체일치</option>
                                                    <option value="2" <?php if ($data['reg_conf_yn_1'] == '2')
                                                        echo "selected"; ?>>전체불일치</option>
                                                </select>
                                            </td>
                                        </tr>

                                        <tr>
                                            <th>매물주소</th>
                                            <td class="d-flex gap-2">
                                                <select class="form-select" name="reg_conf_yn_2" id="reg_conf_yn_2">
                                                    <option value="">-선택-</option>
                                                    <option value="10000" <?php if ($data['reg_conf_yn_2'] == '10000')
                                                        echo "selected"; ?>>일치</option>
                                                    <option value="20000" <?php if ($data['reg_conf_yn_2'] == '20000')
                                                        echo "selected"; ?>>불일치
                                                    </option>
                                                </select>
                                                <input type="text" class="form-control" name="reg_conf_yn_info_2"
                                                    id="reg_conf_yn_info_2"
                                                    value="<?= str_replace(',', '', $data['reg_conf_yn_info_2']) ?>"
                                                    size="20" />
                                            </td>
                                        </tr>
                                        <tr>
                                            <th>의뢰인정보</th>
                                            <td class="d-flex gap-2">
                                                <select class="form-select" name="reg_conf_yn_3" id="reg_conf_yn_3">
                                                    <option value="">-선택-</option>
                                                    <option value="10000" <?php if ($data['reg_conf_yn_3'] == '10000')
                                                        echo "selected"; ?>>일치</option>
                                                    <option value="20000" <?php if ($data['reg_conf_yn_3'] == '20000')
                                                        echo "selected"; ?>>불일치
                                                    </option>
                                                </select>
                                                <input type="text" class="form-control" name="reg_conf_yn_info_3"
                                                    id="reg_conf_yn_info_3"
                                                    value="<?= str_replace(',', '', $data['reg_conf_yn_info_3']) ?>"
                                                    size="20" />
                                            </td>
                                        </tr>

                                        <?php if ($data['vrfc_type_cd'] == "N"): ?>
                                            <tr>
                                                <th>소유자명 확인</th>
                                                <td>
                                                    <select class="form-select" name="ownerVerifiable" id="ownerVerifiable">
                                                        <option value="">-선택-</option>
                                                        <option value="1" <?php if ($data['owner_verifiable'] == "1")
                                                            echo "selected"; ?>>일치</option>
                                                        <option value="0" <?php if ($data['owner_verifiable'] == "0")
                                                            echo "selected"; ?>>불일치</option>
                                                    </select>
                                                </td>
                                            </tr>
                                        <?php endif; ?>
                                        <tr>
                                            <th>메모</th>
                                            <td class="d-flex align-items-end gap-1">
                                                <textarea type="text" class="form-control" name="memo_reg" id="memo_reg"
                                                    style="width:300px; height:45px;resize: none;"><?= $memo['memo'] ?></textarea>

                                                <button class="btn btn-sm btn-light" style="white-space: nowrap;"
                                                    onclick="saveMemo();">
                                                    저장
                                                </button>

                                            </td>
                                        </tr>

                                    </tbody>
                                </table>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div class="card-footer d-flex align-items-center">

                <!-- 왼쪽 버튼 영역 -->
                <?php if (empty($data['cert_register'])): ?>
                    <?php if (
                        (intval($data['stat_cd']) < 45 && intval($data['stat_cd']) >= 35 && intval($data['stat_cd']) != 39) && intval($data['stat_cd']) != 49

                    ): ?>
                        <div class="d-flex gap-1">
                            <button class="btn btn-sm btn-outline-success">
                                <i class="fa fa-fw" aria-hidden="true"></i> 파일업로드
                            </button>

                            <!-- <button class="btn btn-sm btn-outline-secondary">
                            저장
                        </button> -->
                        </div>
                    <?php endif; ?>
                <?php endif; ?>

                <!-- 오른쪽 버튼 영역 -->
                <div class="ms-auto d-flex gap-1">
                    <?php if (
                        (intval($data['stat_cd']) < 45 && intval($data['stat_cd']) >= 35 && intval($data['stat_cd']) != 39) && intval($data['stat_cd']) != 49

                    ): ?>

                        <button type="button" class="btn btn-primary btn-sm" onclick="saveRegi();">
                            저장
                        </button>
                    <?php endif; ?>
                </div>

            </div>
        </div>

        <!-- 정보변경이력 -->
        <div class="main-card mb-3 card">
            <div class="card-body ">
                <h5 class="card-title">정보변경 이력</h5>
                <div class="table-scroll">
                    <table class="table table-bordered table-sm tbl_basic2 apt-info-table">
                        <tr>
                            <th width="90" style="text-align: center;">진행상태</th>
                            <th width="150" style="text-align: center;">변경내용</th>
                            <th width="90" style="text-align: center;">처리자(ID)</th>
                            <th width="120" style="text-align: center;">처리일시</th>
                            <th style="text-align: center;">세부내용</th>
                        </tr>
                        <?php if (!empty($history)) { ?>
                            <?php foreach ($history as $h) { ?>
                                <tr>
                                    <td style="text-align: center;"><?= $h['stat_cd_nm'] ?></td>
                                    <td style="text-align: center;"><?= $h['chg_type'] ?></td>
                                    <td style="text-align: center;"><?= $h['insert_id'] ?></td>
                                    <td style="text-align: center;"><?= $h['insert_tm'] ?></td>
                                    <td><?= $h['memo'] ?></td>

                                <?php } ?>
                            <?php } ?>
                    </table>
                </div>
            </div>
        </div>

    </div>
</div>

<script type="text/javascript">

    //거래구분에 따른 가격설정
    var but_ty = '<?= $data['trade_type_cd'] ?>';
    var regagre = '<?= $data['rgbk_confirm'] ?>';
    var telchkbox = '<?= $tel['file_name'] ?? '' ?>';

    var rlet_type_cd = '<?= $data['rlet_type_cd'] ?>';

    $(function () {

        if (regagre == "0") { //등기부등본 확인여부에 따라 등기부등본 div 표시여부 설정
            $("#regibox").hide();
        }

        if (telchkbox) {	//녹취파일 존재시 checked
            $("#chk_telv").attr("checked", true);
        }

        if (but_ty == "A1") {
            $("#buy_tra_cd3").show();
            $("#div_trade_type_price").show();

            if (rlet_type_cd == "B01" || rlet_type_cd == "B02" || rlet_type_cd == "B03") {
                $("#div_trade_type_price").hide();
                $("#div_trade_type_price2").show();
            }

        } else {
            $("#buy_tra_cd1").show();
            $("#buy_tra_cd2").show();
            $("#buy_tra_cd4").show();
            $("#div_trade_type_price_monthly").show();
        }

        //전화/서류 구분
        $("#atcl_vrtc_way").change(function () {
            if ($("#atcl_vrtc_way").val() == "T") {
                $("#docu_chk").hide();
                $("#call_chk").show();
            } else if ($("#atcl_vrtc_way").val() == "D") {
                $("#docu_chk").show();
                $("#call_chk").hide();
            }
        });

        if ($("#atcl_vrtc_way").val() == "T") {
            $("#docu_chk").hide();
            $("#call_chk").show();
        } else if ($("#atcl_vrtc_way").val() == "D") {
            $("#docu_chk").show();
            $("#call_chk").hide();
        }

        $("#btnModify").on("click", function () {

            $("#atcl_vrtc_way").prop("disabled", false);

            document.getElementById('atcl_amt1').disabled = false;
            document.getElementById('atcl_amt2').disabled = false;
            document.getElementById('atcl_amt3').disabled = false;
            document.getElementById('atcl_amt4').disabled = false;
            document.getElementById('prem_amt').disabled = false;
            document.getElementById('isale_amt').disabled = false;

            $("#price_ignore1").prop("disabled", false);
            $("#price_ignore2").prop("disabled", false);
            $("#priceModify").css("display", "");
            $("#btnSave").prop("disabled", false);

        });

    });

</script>
<?= $this->endSection() ?>